这取决于您使用的操作系统。如果您使用的是Windows,下面的解决方案应该适用于您。在
我添加了一个函数,它将重新应用overriderdirect。这个函数被我们在根目录上使用的绑定调用。在
我还把你的画布改成了一个框架,因为这样更容易管理按钮之类的东西。在
对于linux,您可能需要使用不同的文件类型。你可能需要在windows和windows上使用。在
更新:
我已经添加了iconbitmap和root.tk.call('wm', 'iconphoto', root._w, icon),但是我不确定你是否能够改变你的任务栏图标,直到你至少在windows中编译代码。您可以使用py2exe或freeze。我以前用过freeze,我有一个客户桌面和任务栏图标。在import tkinter as tk
root = tk.Tk()
root.geometry("400x400")
root.overrideredirect(1)
root.resizable(False, False)
root.columnconfigure(0, weight=1)
root.iconbitmap(default='./Colors/small_red.ico')
def close():
root.destroy()
def minimizeWindow():
root.withdraw()
root.overrideredirect(False)
root.iconify()
def check_map(event): # apply override on deiconify.
if str(event) == "":
root.overrideredirect(1)
print ('Deiconified', event)
else:
print ('Iconified', event)
bar_frame = tk.Frame(root)
bar_frame.grid(row=0, column=0, sticky="ew")
bar_frame.columnconfigure(0, weight=1)
icon = tk.PhotoImage(file='./Colors/small_red.gif')
# This appears to have the same results so not sure what the difference is from iconbitmap.
# root.tk.call('wm', 'iconphoto', root._w, icon)
tk.Button(bar_frame, text='x', command=close).grid(row=0, column=1)
tk.Button(bar_frame, text='-', command=minimizeWindow).grid(row=0, column=2)
root.bind('', check_map) # added bindings to pass windows status to function
root.bind('', check_map)
root.mainloop()