0

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!

  • Try something like [this](https://stackoverflow.com/a/66194808/11106801). – TheLizzard May 08 '21 at 12:53
  • No, this is not working. I think this is the issue with ```overrideredirect``` because when I remove that statement, the window gets displayed –  May 08 '21 at 13:37
  • Sorry but I had no way of testing it on MacOS. I tested it on Windows and Linux and it works fine. Anyways it shouldn't call `overrideredirect` unless you are on windows. It should call `self.root.attributes("-type", "splash")` – TheLizzard May 08 '21 at 13:40

3 Answers3

1

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)

0

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



from tkinter import *

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

window.mainloop()

0

ok my answer for mac os, call the function:

from tkinter import *

window = Tk()

window.wm_title = " Your title name "
cottontail
  • 10,268
  • 18
  • 50
  • 51