微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在Mac上的Tkinter中禁用标题栏?

如何解决如何在Mac上的Tkinter中禁用标题栏?

我正在尝试删除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)

然后它将显示一个正常的Mac样式窗口,其三个按钮位于角落。

编辑:我也尝试过

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)

这将显示一个空白窗口。

tkinter blank window on mac

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。