简体   繁体   中英

How to change the title bar in tkinter Mac OS X?

I have seen a number of questions in Stackoverflow asking the same question I have like this . But none of them have an explanation of how to change the title bar in Mac OS X. I'm using python 3.9 in Mac OS.

However, this does not work in Mac. The app is shown in the dock and menubar, but not displayed.

The code from This link does not work either.

Is there any way I can do this?

Thanks in advance!

Hope this anwsers your question https://docs.python.org/3/library/tkinter.html



from tkinter import *

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

window.mainloop()

After some research, I found the way:

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()

NOTE: This code is from this link (Along with minor modifications from my side)

ok my answer for mac os, call the function:

from tkinter import *

window = Tk()

window.wm_title = " Your title name "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM