【发布时间】:2021-05-06 10:32:54
【问题描述】:
我使用的是最新版本的 Mac OS 和 Python 3.9。我尝试使用 overrideredirect 删除标题栏并添加我自己的。但是,结果不显示窗口。该应用程序显示在 Dock 和菜单栏中。但不显示。
我的代码:
from tkinter import *
root = Tk()
def move_window(event):
root.geometry('+{0}+{1}'.format(event.x_root, event.y_root))
root.overrideredirect(True)
root.geometry('400x100+200+200')
title_bar = Frame(root, bg='white', relief='raised', bd=2)
close_button = Button(title_bar, text='X', command=root.destroy)
window = Canvas(root, bg='black')
title_bar.pack(expand=1, fill=X)
close_button.pack(side=RIGHT)
window.pack(expand=1, fill=BOTH)
title_bar.bind('<B1-Motion>', move_window)
root.mainloop()
同样的代码在windows中运行良好。
提前致谢! :)
【问题讨论】:
-
试试this 代码并告诉我它是否有效。 MacOS 是否支持
self.root.attributes("-type", "splash")?