【问题标题】:How to change the colour of tkinter window header without removing it from the taskbar?如何更改 tkinter 窗口标题的颜色而不将其从任务栏中删除?
【发布时间】:2021-08-14 23:06:24
【问题描述】:

我正在 tkinter 中创建一个 GUI,我正在尝试自定义窗口标题以便我可以更改颜色。

我用过:

root.overrideredirect(True)

去掉表头,然后重建了移动标签的功能:

def move_window(event):
    x, y = root.winfo_pointerxy()
    root.geometry(f"+{x-650}+{y}")

title_bar = tk.Frame(root, bg=pallete["pallete1"], bd=0,height=22)
title_bar.config(highlightthickness=2, highlightcolor= pallete["pallete3"])
title_bar.pack(fill="x")
title_bar.bind('<B1-Motion>', move_window)

只有这样,当我overrideredirect去掉窗口标题时,程序在任务栏中消失了,所以你找不到了。

我只是想知道是否有办法解决这个问题或更改窗口标题而不必删除它并重建一个新的。

【问题讨论】:

  • 这能回答你的问题吗? Can I change the title bar in Tkinter?
  • @nbk 不,那是我最初查看并使用他们的一些代码但仍然无法工作的地方
  • 所以你在 overrideriderct 时寻找拖动胜利?或者如果你缩小你的应用程序,你需要那个图标?在这里覆盖是 TheLizzard = stackoverflow.com/questions/66968676/… 的完美答案。我不清楚你到底是什么意思。还有一个选项iconify 你可以使用它覆盖
  • 接受的答案将标题栏的颜色更改为您输入的颜色,我尝试使用绿色而不是白色,所以您能解释一下该答案不适合的地方吗?
  • @nbk 接受的答案允许您移动和关闭屏幕,我希望能够最小化然后从任务栏再次打开它。 root.overrideredirect(True) 不在任务栏中显示程序。

标签: python user-interface tkinter header window


【解决方案1】:
   
 def minsize():                    # minsize func() for your button
        root.overrideredirect(0)   # minsize window and iconify
        root.iconify()

def showwindow(event):
        root.overrideredirect(1)
        root.iconify()

使用map将此绑定到您的标题栏

your_widdgget.bind("<Map>", lambda event: showindow(event)) # in this case i don't know why lambda but it still works for me

【讨论】:

  • 救世主现在工作我仍然需要调整一些东西以适应我的程序,但非常感谢!
  • 如果你有这个TclError你可以except TclError:通过......我没有找到更好的解决方案。也许其他人知道如何更好地处理它。
  • 这里的'Map' 是什么?它是'&lt;Map&gt;'。你不需要lambda。
  • 我发布了&lt;Map&gt;不知道为什么Map
猜你喜欢
  • 2022-08-15
  • 2017-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多