【问题标题】:Remove titlebar without overrideredirect() using Tkinter?使用 Tkinter 删除没有 overrideredirect() 的标题栏?
【发布时间】:2017-01-24 13:42:48
【问题描述】:

我目前正在 Linux 上使用 Tkinter 和 Python 2.7,我想知道是否有一种方法可以在不使用 overrideredirect(1) 的情况下删除 TK() 窗口边框和标题栏。

我有自己的关闭按钮,overrideredirect(1) 向我提出了一些我无法接受的问题:

我不能使用attributes("-fullscreen", True),因为标题栏和边框仍然存在。

【问题讨论】:

    标签: python tkinter


    【解决方案1】:

    窗口装饰全部由窗口管理器处理,因此您要做的是找到一种方法来告诉窗口管理器以不同于标准应用程序窗口的方式装饰您的窗口。 Tk 提供overrideredirect 让窗口管理器完全忽略此窗口,但我们也可以使用Extended Window Manager Hints 向窗口管理器声明此顶层窗口的预期用途。例如,工具提示和闪屏窗口会这样做,以允许管理器提供最少的装饰和可能的特殊动画。

    在您的情况下,添加“飞溅”提示应该可以满足您的需求

    root = tk.Tk()
    root.wm_attributes('-type', 'splash')
    

    为此,您需要 Tk 8.5 或更高版本。

    【讨论】:

    • 感谢您的回复,这是用于 Linux、Windows 还是两者?我目前在 Windows 上使用 Python 3.5 和 Tkinter 8.6,我收到此错误:_tkinter.TclError: wrong # args: should be "wm attributes window ?-alpha ?double?? ?-transparentcolor ?color?? ?-disabled ?bool?? ?-fullscreen ?bool?? ?-toolwindow ?bool?? ?-topmost ?bool??"_
    • 这太棒了 - 刚刚在 Linux 上进行了测试,它运行良好! (到目前为止)
    • -type 选项仅与 X 相关,因为它是 X 窗口管理器使用的系统。提示 359 有详细信息 (tcl.tk/cgi-bin/tct/tip/359.html)。您可以检查 root.tk.call('tk','windowingsystem') 的“x11”并使用它来避免在其他系统上使用此功能。
    • @uniqueNt 如果您需要修改overrideredirect Tk 窗口的窗口样式,可能stackoverflow.com/a/30819099/291641 可以在Windows 上为您提供帮助。
    • @patthoyts 成功了,非常感谢。你刚刚向我捐赠了一条生命:D
    【解决方案2】:

    您必须在您的命令之前给出您的根窗口名称。

    像这样:

    from tkinter import *
    
    root=Tk()
    root.wm_attributes('-fullscreen','true')
    root.mainloop()
    

    【讨论】:

      猜你喜欢
      • 2012-08-04
      • 2021-09-28
      • 1970-01-01
      • 1970-01-01
      • 2019-03-13
      • 1970-01-01
      • 2022-06-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多