1

I am trying to remove the title bar of a tkinter window. I want to make a custom title bar. I have searched for this answer and I found this.

import tkinter as tk
root = tk.Tk()
# eliminate the titlebar
root.overrideredirect(1)
# your code here ...
root.mainloop()

When I run this code, the code runs without an error, but no window shows. If I replace

root.overrideredirect(1)

with

root.overrideredirect(0)

then it will show a normal mac style window with the three buttons in the corner.

Edit: I have also tried this

import tkinter as tk
root = tk.Tk()
# eliminate the titlebar

root.wm_attributes('-type', 'splash')

# your code here ...
root.mainloop()

This is the error message that I get

Traceback (most recent call last):
  File "no-bar.py", line 5, in <module>
    root.wm_attributes('-type', 'splash')
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/__init__.py", line 1967, in wm_attributes
    return self.tk.call(args)
_tkinter.TclError: bad attribute "-type": must be -alpha, -fullscreen, -modified, -notify, -titlepath, -topmost, or -transparent

What can I do to create a tkinter window without a title bar?

Python 3.8.1 MacOS 10.15.6

Tkoz
  • 41
  • 5

3 Answers3

3

EDIT: This only applies to tk/tcl versions < 6.8.10 on macOS

After searching a bit, I found the answer for mac users.

If you only use

root.overrideredirect(1)

Then the window will be hidden on a mac. So you need to add one more line of code so it looks like this

root.overrideredirect(1)
root.overrideredirect(0)

This will show a blank window.

tkinter blank window on mac

Tkoz
  • 41
  • 5
0

Try this:

root.wm_attributes('-type', 'splash')

instead of

root.overrideredirect(1)

I am not sure if this works. Also, I can't test it as I am not a Mac user.

Devansh Soni
  • 771
  • 5
  • 16
  • I added an edit to show the error message that I get. I have a feeling this is a mac issue, but not entirely sure. – Tkoz Aug 27 '20 at 21:25
  • 1
    I figured out the answer. root.overrideredirect(True) hides the window on a mac. So you have to add root.overrideredirect(False) after it and it will show a blank window. – Tkoz Aug 28 '20 at 04:10
  • But on Windows and Linux OS, only first line is required to hide the title bar. Btw, thanks for informing. – Devansh Soni Aug 28 '20 at 08:49
0

I think it also works on tk/tcl 8.6.8 But you need to write like this:

            root = tk.Tk()
            root.overrideredirect(True)
            root.overrideredirect(False)

If you add anything between line1 and line2,3, like below, it won't work correctly.

DONT DO THIS!
            root = tk.Tk()

            root.configure(background='#292929')
            root.attributes('-alpha', 0.9)
            root.title('Monitor v{0}'.format(VER))
            size = '%dx%d+%d+%d' % (340, 200, 0, 0)
            root.geometry(size)
            root.resizable(width=False, height=False)
            root.protocol('WM_DELETE_WINDOW', lambda: sys.exit(0))

            root.overrideredirect(True)
            root.overrideredirect(False)
Arthur Zhou
  • 33
  • 2
  • 4