hallo leutz!
da pywin32 (noch) nicht fuer python 3 verfuegbar ist, muss ich auf SysTrayIcon.py verzichten.
tcl's winico koennte eine alternative sein
mein einziges problem ist, dass Tk fenster nicht ueber die (windows) tray bar overlappen
Wie kann ich einen tkinter fenster so konfigurieren, dass er nicht hinter der tray bar (das ding ganz unten wo alle minimierte fenster usw sind) kommt?
Code: Alles auswählen
from tkinter import *
class TrayIcon(Tk):
def __init__(self, icon_path, text):
Tk.__init__(self)
self.withdraw()
self.eval('load "E:/winico0.6/Winico06.dll"')
self.eval('package require Winico')
self.set_icon(icon_path)
self.createcommand('iconcb', self._event_handler)
self.eval('winico taskbar add $ico -pos 1 -text {0} -callback "iconcb %m %x %y"'.format('"' + text.replace('"', r'\"') + '"'))
def set_icon(self, icon_path):
if self.call('info', 'exists', 'ico'):
self.eval('winico delete $ico')
self.call('set', 'ico', self.call('winico', 'create', icon_path))
def _event_handler(self, event, x, y):
if event == 'WM_RBUTTONDOWN':
self._show(x, y)
elif event == 'WM_LBUTTONDOWN':
pass
#self.double_click_cb()
#def hide(self):
# print('hiding')
# self.withdraw()
def _show(self, x, y):
print('showing', x, y)
self.deiconify()
self.geometry('+{0}+{1}'.format(int(x)-self.winfo_width(), int(y)-self.winfo_height()))
self.overrideredirect(1)
def mk_menu(self, menu_list):
for child in self.children.values():
child.destroy()
for text, cb in menu_list:
Button(self, text=text, command=lambda: (self.withdraw(),cb())).pack()
def main():
trayicon = TrayIcon('E:/winico0.6/smiley.ico', 'doubleclick me!')
trayicon.mk_menu([('test', lambda: 0)]*10)
trayicon.mainloop()
if __name__ == '__main__':
main()