问题描述
我正在尝试删除tkinter窗口的标题栏。我想制作一个自定义标题栏。我已经找到了答案,找到了。
import tkinter as tk
root = tk.Tk()
# eliminate the titlebar
root.overrideredirect(1)
# your code here ...
root.mainloop()
当我运行此代码时,该代码运行无错误,但没有窗口显示。如果我更换
root.overrideredirect(1)
使用
root.overrideredirect(0)
编辑:我也尝试过
import tkinter as tk
root = tk.Tk()
# eliminate the titlebar
root.wm_attributes('-type','splash')
# your code here ...
root.mainloop()
这是我收到的错误消息
Traceback (most recent call last):
File "no-bar.py",line 5,in <module>
root.wm_attributes('-type','splash')
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/__init__.py",line 1967,in wm_attributes
return self.tk.call(args)
_tkinter.TclError: bad attribute "-type": must be -alpha,-fullscreen,-modified,-notify,-titlepath,-topmost,or -transparent
如何创建没有标题栏的tkinter窗口?
Python 3.8.1 MacOS 10.15.6
解决方法
尝试一下:
root.wm_attributes('-type','splash')
代替
root.overrideredirect(1)
我不确定是否可行。另外,由于我不是Mac用户,因此无法对其进行测试。
,编辑:这仅适用于macOS上的tk / tcl版本
经过一番搜索,我找到了Mac用户的答案。
如果您仅使用
root.overrideredirect(1)
然后该窗口将在Mac上隐藏。因此,您需要再添加一行代码,使其看起来像这样
root.overrideredirect(1)
root.overrideredirect(0)
这将显示一个空白窗口。