16

I'm currently working with Tkinter and Python 2.7 on Linux and I was wondering if there was a way to remove the TK() window border frame and title bar without using overrideredirect(1).

I have my own close button and overrideredirect(1) presents me with a few issues that I can't accept:

I can't use attributes("-fullscreen", True) as the titlebar and borders remain.

martineau
  • 119,623
  • 25
  • 170
  • 301
D'Arcy
  • 383
  • 1
  • 4
  • 11

2 Answers2

22

The window decoration is all handled by the window manager so what you are trying to do is find a way to tell the window manager to decorate your window differently from a standard application window. Tk provides overrideredirect to have the window manager completely ignore this window but we can also use Extended Window Manager Hints to declare the intended use of this toplevel window to the window manager. This is done for instance for tooltip and splashscreen windows to allow the manager to provide minimal decoration and possibly special animations.

In your case, adding a 'splash' hint should do what you want

root = tk.Tk()
root.wm_attributes('-type', 'splash')

You will need Tk 8.5 or above for this.

patthoyts
  • 32,320
  • 3
  • 62
  • 93
  • 12
    Thanks for your reply, is this for use on Linux, Windows or Both? I'm currently on Windows using Python 3.5 and Tkinter 8.6 and I get this error: `_tkinter.TclError: wrong # args: should be "wm attributes window ?-alpha ?double?? ?-transparentcolor ?color?? ?-disabled ?bool?? ?-fullscreen ?bool?? ?-toolwindow ?bool?? ?-topmost ?bool??"`_ – D'Arcy Sep 16 '16 at 11:58
  • This is amazing - just tested it on Linux and it works perfectly! (so far) – D'Arcy Sep 16 '16 at 12:17
  • 3
    The `-type` option is only relevant to X as it is a system used by X Window managers. TIP 359 has the details (http://www.tcl.tk/cgi-bin/tct/tip/359.html). You can check `root.tk.call('tk','windowingsystem')` for "x11" and use that to avoid using this feature on other systems. – patthoyts Sep 16 '16 at 12:58
  • @D'Arcy I got the same error, no idea how to solve :( – tiwarinitin94 Mar 13 '18 at 12:32
  • 3
    @uniqueNt Possibly https://stackoverflow.com/a/30819099/291641 can help you on Windows if you need to modify the windows style of an overrideredirect Tk window. – patthoyts Mar 13 '18 at 19:06
  • There are lots of window decoration questions and answers. I revisit the subject a couple times a year. After a few years I finally found this answer that works like a charrm :) – WinEunuuchs2Unix Jun 21 '23 at 23:58
4

You must give your root window name before your command.

Like this:

from tkinter import *

root=Tk()
root.wm_attributes('-fullscreen','true')
root.mainloop()
Mohammad Yusuf
  • 16,554
  • 10
  • 50
  • 78
abhi krishnan
  • 65
  • 1
  • 1