【问题标题】:How to change the title bar in tkinter Mac OS X?如何更改 tkinter Mac OS X 中的标题栏?
【发布时间】:2021-07-30 12:27:45
【问题描述】:

我在 Stackoverflow 中看到了很多问题,都在问我喜欢 this 的问题。但是他们都没有解释如何在 Mac OS X 中更改标题栏。我在 Mac OS 中使用 python 3.9。

但是,这在 Mac 中不起作用。该应用程序显示在 Dock 和菜单栏中,但不显示。

代码来自 This link 也不起作用。

有什么办法可以做到吗?

提前致谢!

【问题讨论】:

  • 试试this
  • 不,这不起作用。我认为这是overrideredirect 的问题,因为当我删除该语句时,会显示窗口
  • 抱歉,我无法在 MacOS 上测试它。我在 Windows 和 Linux 上对其进行了测试,效果很好。无论如何,除非您在 Windows 上,否则不应调用 overrideredirect。它应该调用self.root.attributes("-type", "splash")

标签: python tkinter titlebar


【解决方案1】:

希望这能回答您的问题 https://docs.python.org/3/library/tkinter.html



from tkinter import *

window = Tk()
window.title("New Title")

window.mainloop()

【讨论】:

  • 感谢您的回答,但我想问的是关于更改标题栏的问题。
【解决方案2】:

经过一番研究,我找到了方法:

from tkinter import *

root = Tk()


def get_pos(event):
    xwin = root.winfo_x()
    ywin = root.winfo_y()
    startx = event.x_root
    starty = event.y_root

    ywin = ywin - starty
    xwin = xwin - startx

    def move_window(event):
        root.geometry("400x100" + '+{0}+{1}'.format(event.x_root + xwin, event.y_root + ywin))

    startx = event.x_root
    starty = event.y_root

    title_bar.bind('<B1-Motion>', move_window)

root.overrideredirect(1)
root.overrideredirect(0)  
root.geometry('400x100+200+200') 

title_bar = Frame(root, bg='white', relief='raised', bd=2)

close_button = Button(title_bar, text='X', command=root.destroy)

window = Canvas(root, bg='black')

title_bar.pack(expand=1, fill=X)
close_button.pack(side=RIGHT)
window.pack(expand=1, fill=BOTH)

title_bar.bind('<B1-Motion>', get_pos)
title_bar.bind('<Button-1>', get_pos)
root.mainloop()

注意:此代码来自this link(以及我这边的小修改)

【讨论】:

    猜你喜欢
    • 2015-07-12
    • 1970-01-01
    • 2011-04-29
    • 1970-01-01
    • 2020-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多