2

I have searched wide and far for this question, but noone seems to know. I create a simple tkinter window (tcl 8.5) in python 2.7 and want it maximized, just as if I would hit the maximize button in top right corner. Using the -fullscreen option is not an option since it removes the title bar.

I tried the following:

import Tkinter

root = Tkinter.Tk()
root.overrideredirect(True)
# Set window to be size of screen
root.geometry("{0}x{1}+0+0".format(root.winfo_screenwidth(), root.winfo_screenheight()))  

The problem is that the window is now below the Windows taskbar and some of my elements are therefore not shown. An easy hack would be to set height to screenheight-some_constant, or calculate some_constant based on data from the operating system. However, this seems like an extremely ugly hack.

Is there any way to maximize a window in tkinter in a clean way where the window is above the (Windows) taskbar and still has a title bar?

Pphoenix
  • 1,423
  • 1
  • 15
  • 37
  • take a look at http://stackoverflow.com/a/22275334/1107807 if it helps you should point to the original answer. – Don Question Jun 25 '14 at 11:01
  • 1
    Tried but it cannot find the option `-zoomed`. Probably added in a later tkinter version, updating question with version info. – Pphoenix Jun 25 '14 at 11:30

1 Answers1

6

i know this is an old question but i have tested the following code on an XP system (32bit) with python 2.7.6, using TCL version 8.5 and tk version 8.5.

code:

import Tkinter as tk

root = tk.Tk()

root.state("zoomed")

root.mainloop()

this does start the window maximised on the primary monitor.
it does have pitfalls - i have been unable to make it maximise on another monitor, but does work reliably without covering the title bar or taskbar.

and as you want to keep the title bar i would leave out the overrideredirect.

James Kent
  • 5,763
  • 26
  • 50
  • 1
    no problem, i found through my own blundering about with tkinter that alot of options that can be used with tk can also be used with tkinter if you drop the - in front of it, but not all for some reason... – James Kent Jan 09 '15 at 17:24