【问题标题】:Python Tkinter: Remove window borderPython Tkinter:删除窗口边框
【发布时间】:2014-09-30 01:16:53
【问题描述】:

如何在不使用 overrideredirect 的情况下移除 TopLevel 的边框?

TopLevel.overrideredirect(True)

如果能提供示例代码就好了。

Python 2.7.3、Linux、Tkinter 版本 $Revision: 81008 $

【问题讨论】:

  • overrideredirect 有什么问题?它存在的原因正是您所要求的——删除窗口管理器边框。
  • 好吧,我制作了一个进度条,并通过使用 overrideredirect 隐藏了边框。但是,当我执行 TopLevel.transient(parentWindow) 时它不起作用。我使用瞬态的原因是因为我想在其父级也最小化后最小化进度条。但是如果 overrideredirect 设置为 True,使用 TopLevel.transient(parentWindow) 不会做任何事情
  • 你能使用相当于Windows WinAPI的Linux吗?
  • 我只能在 Linux 上运行我的代码,如果这就是你的意思 :)
  • 我的意思是我不知道如何直接在 Tk 中执行此操作,但我可以通过 4 行代码使用窗口句柄和 WinAPI 调用来执行此操作,而不会产生任何副作用。 Linux中应该有类似的东西。

标签: python python-2.7 tkinter border


【解决方案1】:

在 Bryan Oakley 的帮助下,我实现了一个解决方案,可以让我在解决问题时使用“overrideredirect”,那就是使用“Unmap”事件。

以下示例代码显示了当使用'Map'和'Unmap'时附加窗口可以与主窗口一起最小化:

import Tkinter
class App:
    def __init__(self):
        self.root = Tkinter.Tk()
        Tkinter.Label(self.root, text="main window").pack()
        self.window = Tkinter.Toplevel()
        self.window.overrideredirect(True)
        Tkinter.Label(self.window, text="Additional window").pack()
        self.root.bind("<Unmap>", self.OnUnMap)
        self.root.bind("<Map>", self.OnMap)
        self.root.mainloop()
    def OnMap(self, e):
        self.window.wm_deiconify()
    def OnUnMap(self, e):
        self.window.wm_withdraw()
app=App()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多