[英]Making Tkinter windows show up in the taskbar
我想讓我的程序顯示在任務欄中,但仍然沒有傳統的Windows寄宿生。 我該怎么辦? 我知道self.overrideredirect(1) ,但是這從任務欄中刪除了我的程序。
這適用於Windows 7。
我沒有斷言這是“正確”的方法,但是請看這是否對您有用:
try:
from tkinter import *
except ImportError:
from Tkinter import *
class NewRoot(Tk):
def __init__(self):
Tk.__init__(self)
self.attributes('-alpha', 0.0)
class MyMain(Toplevel):
def __init__(self, master):
Toplevel.__init__(self, master)
self.overrideredirect(1)
self.attributes('-topmost', 1)
self.geometry('+100+100')
self.bind('<ButtonRelease-3>', self.on_close) #right-click to get out
def on_close(self, event):
self.master.destroy()
if __name__ == '__main__':
root = NewRoot()
root.lower()
root.iconify()
root.title('Spam 2.0')
app = MyMain(root)
app.mainloop()
您可以在根對象下添加一個頂層窗口,使根目錄不可見,然后處理圖標事件以隱藏或顯示頂層窗口。
root = tkinter.Tk()
top = tkinter.Toplevel(root)
top.overrideredirect(1) #removes border but undesirably from taskbar too (usually for non toplevel windows)
root.attributes("-alpha",0.0)
#toplevel follows root taskbar events (minimize, restore)
def onRootIconify(event): top.withdraw()
root.bind("<Unmap>", onRootIconify)
def onRootDeiconify(event): top.deiconify()
root.bind("<Map>", onRootDeiconify)
window = tkinter.Frame(master=top)
window.mainloop()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.