Reputation: 61
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
Upvotes: 2
Views: 1205
Reputation: 53
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)
Upvotes: 0
Reputation: 61
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.
Upvotes: 4
Reputation: 771
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.
Upvotes: 0