日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

python3 tkinter寫出來的程序最小化到系統托盤

瀏覽:153日期:2022-09-06 15:24:09

問題描述

python3 tkinter寫出來的程序點擊關閉,最小化到系統托盤

問題解答

回答1:

其實就是windowsApi的一層封裝。

#!/usr/bin/env python# Module : SysTrayIcon.py# Synopsis : Windows System tray icon.# Programmer : Simon Brunning - simon@brunningonline.net# Date : 11 April 2005# Notes : Based on (i.e. ripped off from) Mark Hammond’s# win32gui_taskbar.py and win32gui_menu.py demos from PyWin32’’’TODOFor now, the demo at the bottom shows how to use it...’’’ import osimport sysimport win32apiimport win32conimport win32gui_structtry: import winxpgui as win32guiexcept ImportError: import win32guiclass SysTrayIcon(object): ’’’TODO’’’ QUIT = ’QUIT’ SPECIAL_ACTIONS = [QUIT]FIRST_ID = 1023def __init__(self, icon, hover_text, menu_options, on_quit=None, default_menu_index=None, window_class_name=None,):self.icon = iconself.hover_text = hover_textself.on_quit = on_quitmenu_options = menu_options + ((’Quit’, None, self.QUIT),)self._next_action_id = self.FIRST_IDself.menu_actions_by_id = set()self.menu_options = self._add_ids_to_menu_options(list(menu_options))self.menu_actions_by_id = dict(self.menu_actions_by_id)del self._next_action_idself.default_menu_index = (default_menu_index or 0)self.window_class_name = window_class_name or 'SysTrayIconPy'message_map = {win32gui.RegisterWindowMessage('TaskbarCreated'): self.restart, win32con.WM_DESTROY: self.destroy, win32con.WM_COMMAND: self.command, win32con.WM_USER+20 : self.notify,}# Register the Window class.window_class = win32gui.WNDCLASS()hinst = window_class.hInstance = win32gui.GetModuleHandle(None)window_class.lpszClassName = self.window_class_namewindow_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW;window_class.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)window_class.hbrBackground = win32con.COLOR_WINDOWwindow_class.lpfnWndProc = message_map # could also specify a wndproc.classAtom = win32gui.RegisterClass(window_class)# Create the Window.style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENUself.hwnd = win32gui.CreateWindow(classAtom, self.window_class_name, style, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hinst, None)win32gui.UpdateWindow(self.hwnd)self.notify_id = Noneself.refresh_icon()win32gui.PumpMessages() def _add_ids_to_menu_options(self, menu_options):result = []for menu_option in menu_options: option_text, option_icon, option_action = menu_option if callable(option_action) or option_action in self.SPECIAL_ACTIONS:self.menu_actions_by_id.add((self._next_action_id, option_action))result.append(menu_option + (self._next_action_id,)) elif non_string_iterable(option_action):result.append((option_text, option_icon, self._add_ids_to_menu_options(option_action), self._next_action_id)) else:print ’Unknown item’, option_text, option_icon, option_action self._next_action_id += 1return result def refresh_icon(self):# Try and find a custom iconhinst = win32gui.GetModuleHandle(None)if os.path.isfile(self.icon): icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE hicon = win32gui.LoadImage(hinst, self.icon, win32con.IMAGE_ICON, 0, 0, icon_flags)else: print 'Can’t find icon file - using default.' hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)if self.notify_id: message = win32gui.NIM_MODIFYelse: message = win32gui.NIM_ADDself.notify_id = (self.hwnd, 0, win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP, win32con.WM_USER+20, hicon, self.hover_text)win32gui.Shell_NotifyIcon(message, self.notify_id) def restart(self, hwnd, msg, wparam, lparam):self.refresh_icon() def destroy(self, hwnd, msg, wparam, lparam):if self.on_quit: self.on_quit(self)nid = (self.hwnd, 0)win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, nid)win32gui.PostQuitMessage(0) # Terminate the app. def notify(self, hwnd, msg, wparam, lparam):if lparam==win32con.WM_LBUTTONDBLCLK: self.execute_menu_option(self.default_menu_index + self.FIRST_ID)elif lparam==win32con.WM_RBUTTONUP: self.show_menu()elif lparam==win32con.WM_LBUTTONUP: passreturn True def show_menu(self):menu = win32gui.CreatePopupMenu()self.create_menu(menu, self.menu_options)#win32gui.SetMenuDefaultItem(menu, 1000, 0)pos = win32gui.GetCursorPos()# See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.aspwin32gui.SetForegroundWindow(self.hwnd)win32gui.TrackPopupMenu(menu,win32con.TPM_LEFTALIGN,pos[0],pos[1],0,self.hwnd,None)win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)def create_menu(self, menu, menu_options):for option_text, option_icon, option_action, option_id in menu_options[::-1]: if option_icon:option_icon = self.prep_menu_icon(option_icon)if option_id in self.menu_actions_by_id:item, extras = win32gui_struct.PackMENUITEMINFO(text=option_text, hbmpItem=option_icon, wID=option_id)win32gui.InsertMenuItem(menu, 0, 1, item) else:submenu = win32gui.CreatePopupMenu()self.create_menu(submenu, option_action)item, extras = win32gui_struct.PackMENUITEMINFO(text=option_text, hbmpItem=option_icon, hSubMenu=submenu)win32gui.InsertMenuItem(menu, 0, 1, item) def prep_menu_icon(self, icon):# First load the icon.ico_x = win32api.GetSystemMetrics(win32con.SM_CXSMICON)ico_y = win32api.GetSystemMetrics(win32con.SM_CYSMICON)hicon = win32gui.LoadImage(0, icon, win32con.IMAGE_ICON, ico_x, ico_y, win32con.LR_LOADFROMFILE)hdcBitmap = win32gui.CreateCompatibleDC(0)hdcScreen = win32gui.GetDC(0)hbm = win32gui.CreateCompatibleBitmap(hdcScreen, ico_x, ico_y)hbmOld = win32gui.SelectObject(hdcBitmap, hbm)# Fill the background.brush = win32gui.GetSysColorBrush(win32con.COLOR_MENU)win32gui.FillRect(hdcBitmap, (0, 0, 16, 16), brush)# unclear if brush needs to be feed. Best clue I can find is:# 'GetSysColorBrush returns a cached brush instead of allocating a new# one.' - implies no DeleteObject# draw the iconwin32gui.DrawIconEx(hdcBitmap, 0, 0, hicon, ico_x, ico_y, 0, 0, win32con.DI_NORMAL)win32gui.SelectObject(hdcBitmap, hbmOld)win32gui.DeleteDC(hdcBitmap)return hbm def command(self, hwnd, msg, wparam, lparam):id = win32gui.LOWORD(wparam)self.execute_menu_option(id) def execute_menu_option(self, id):menu_action = self.menu_actions_by_id[id] if menu_action == self.QUIT: win32gui.DestroyWindow(self.hwnd)else: menu_action(self) def non_string_iterable(obj): try:iter(obj) except TypeError:return False else:return not isinstance(obj, basestring)# Minimal self test. You’ll need a bunch of ICO files in the current working# directory in order for this to work...if __name__ == ’__main__’: import itertools, globicons = itertools.cycle(glob.glob(’*.ico’)) hover_text = 'SysTrayIcon.py Demo' def hello(sysTrayIcon): print 'Hello World.' def simon(sysTrayIcon): print 'Hello Simon.' def switch_icon(sysTrayIcon):sysTrayIcon.icon = icons.next()sysTrayIcon.refresh_icon() menu_options = ((’Say Hello’, icons.next(), hello), (’Switch Icon’, None, switch_icon), (’A sub-menu’, icons.next(), ((’Say Hello to Simon’, icons.next(), simon), (’Switch Icon’, icons.next(), switch_icon), )) ) def bye(sysTrayIcon): print ’Bye, then.’SysTrayIcon(icons.next(), hover_text, menu_options, on_quit=bye, default_menu_index=1)

標簽: Python 編程
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
欧美精品二区| 欧美日韩国产免费观看视频| 美女久久一区| 亚洲欧美网站| 水野朝阳av一区二区三区| 美日韩一区二区三区| 精品国产一区二| 色爱综合网欧美| 中日韩男男gay无套| 免费成人在线视频观看| 日韩亚洲精品在线观看| 99精品美女| 国产一区二区久久久久| 日韩国产在线不卡视频| 日韩av网站在线观看| 福利视频一区| 蜜桃视频第一区免费观看| 国户精品久久久久久久久久久不卡| 亚洲欧美高清| 精品一区二区三区中文字幕| 美女精品在线观看| 日韩一区二区三免费高清在线观看| 98精品久久久久久久| 亚洲一区二区三区高清不卡| 欧美韩一区二区| 最新国产拍偷乱拍精品| 伊人久久大香伊蕉在人线观看热v| 丝袜美腿亚洲色图| 免费av一区| 欧美一级一区| 国产传媒在线观看| 久久伊人亚洲| 国产精品一区亚洲| 91精品综合| 国产精品99精品一区二区三区∴| 国产96在线亚洲| 久久精品99国产精品日本| 日韩国产激情| 国产精品久久久久久久久久10秀 | 国产精品极品在线观看| 色欧美自拍视频| 在线亚洲成人| 四虎精品永久免费| 国产一区二区色噜噜| 91成人精品| 国产亚洲久久| 免费毛片在线不卡| 人人爱人人干婷婷丁香亚洲| 中文字幕在线官网| 亚洲欧美在线综合| 日韩大片在线播放| 日韩欧美中文字幕在线视频| 精品国产a一区二区三区v免费| 久久精品在线| 欧美一区激情| 国产99亚洲| 国产精品日本一区二区不卡视频| 日韩不卡在线| 日韩1区2区3区| 欧美成a人国产精品高清乱码在线观看片在线观看久 | 欧美羞羞视频| 亚洲三级网址| 天堂√8在线中文| 亚洲综合激情在线| 日韩国产在线| 日本午夜免费一区二区| 一区二区三区四区在线看| 国产精品一区二区精品视频观看| 在线一区电影| 国产精品精品| 日本不卡不码高清免费观看 | 免费日韩视频| 在线手机中文字幕| 日本视频在线一区| 亚洲精品在线观看91| 美女高潮久久久| 免费人成网站在线观看欧美高清| 成年男女免费视频网站不卡| 日韩激情中文字幕| 黄色亚洲在线| 国产美女高潮在线| 国产日韩视频在线| 视频一区视频二区中文字幕| 麻豆精品在线视频| 亚洲日本久久| 日韩视频中文| 国产综合色区在线观看| 国产高清亚洲| 在线日韩成人| 欧美理论视频| 激情亚洲影院在线观看| 久久99免费视频| 日韩二区三区四区| 午夜一区在线| 欧美日韩一二三四| 国产理论在线| 狂野欧美性猛交xxxx| 天堂精品久久久久| 国产在线不卡| 日韩成人综合| 日韩av在线中文字幕| 国产精品亚洲二区| 日本特黄久久久高潮| 亚洲最新av| 蜜桃一区二区三区在线| 欧美另类综合| 国内精品福利| 久久香蕉国产| 精精国产xxxx视频在线野外| 国产精品二区不卡| 成人国产精品久久| 国产成人免费av一区二区午夜| 久久99久久人婷婷精品综合| 青草久久视频| 欧美另类中文字幕| 欧美日韩一视频区二区| 欧美综合精品| 国产精品夜夜夜| 国产精品jk白丝蜜臀av小说| 国产精品网站在线看| 国产午夜精品一区在线观看| 欧美日本二区| 国产精品视频3p| 国产精品亚洲四区在线观看| 久久国产日韩欧美精品| 国产亚洲观看| 国产精品3区| 精品国产亚洲日本| 久久免费精品| 国产一区二区三区四区五区传媒 | 久久伦理在线| 欧美网站在线| 久久香蕉精品| 婷婷视频一区二区三区| 欧美影院视频| 你懂的网址国产 欧美| 麻豆精品在线| аⅴ资源天堂资源库在线| 日韩欧美精品一区| 久久精品免费一区二区三区| 日韩久久一区二区三区| 久久精品青草| 国产99久久| 丝袜美腿亚洲色图| 青草av.久久免费一区| 国产福利一区二区精品秒拍| 国产va免费精品观看精品视频| 超碰在线99| 激情综合网站| 亚洲精品乱码| 国产精品va视频| 日韩伦理福利| 黑丝美女一区二区| 综合国产在线| 国产精品久久久久久久久免费高清 | 久久永久免费| 欧美香蕉视频| 丝袜a∨在线一区二区三区不卡| 91亚洲无吗| 高清av不卡| 免费久久99精品国产自在现线| 亚洲人成毛片在线播放女女| 国产欧美欧美| 亚洲va中文在线播放免费| 亚洲欧美日韩国产| 国产欧美激情| 色88888久久久久久影院| 国产精品呻吟| 国产精品chinese| 婷婷亚洲五月色综合| 91嫩草精品| 欧美日韩精品免费观看视欧美高清免费大片 | 男女性色大片免费观看一区二区| 欧美一区免费| 欧美片第1页| 最近国产精品视频| 欧美www视频在线观看| 国产精品美女久久久| 欧美偷窥清纯综合图区| 欧美成人精品三级网站| 日韩三级精品| 日韩在线短视频| 日韩极品在线观看| 91精品韩国| 日韩av电影一区| 欧美日韩在线观看视频小说| 奇米亚洲欧美| 婷婷亚洲综合| 精品国产午夜| 一区二区三区网站| 国产在线看片免费视频在线观看| 久久亚洲色图| 国产va在线视频| 日本不卡视频在线| 丝袜av一区| 你懂的网址国产 欧美| 亚洲欧美日韩综合国产aⅴ| 国产一区二区三区日韩精品| 日韩制服丝袜av| 日韩欧美一区免费|