Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tkinter python maximize window

People also ask

How do you maximize a window in Python?

Build A Paint Program With TKinter and Python We can customize the geometry of the window using the geometry method. However, in order to maximize the window, we can use the state() method which can be used for scaling the tkinter window. It maximizes the window after passing the “zoomed” state value to it.

How do I make tkinter window full screen?

Tkinter displays the application window by its default size. However, we can display a full-screen window by using attributes('fullscreen', True) method. The method is generally used for assigning a tkinter window with properties like transparentcolor, alpha, disabled, fullscreen, toolwindow, and topmost.

How do I make my tkinter bigger?

Python Tkinter – Set Window Size But, you can also control the window size by setting a specific width and height to the window. You can set the size of Tkinter window by calling geometry() function on the window with width and height string passed as argument.

How do you change the frame size in Python?

By default, Tkinter Frame fits to its children and thus its width and height depends on its children. You can override this behavior and force a specific width and height to the frame. To force the width and height of frame widget call pack_propagate(0) on the frame.


You can do it by calling

root.state('zoomed')

If you want to set the fullscreen attribute to True, it is as easy as:

root = Tk()
root.attributes('-fullscreen', True)

However, it doesn't show the title bar. If you want to keep it visible, you can resize the Tk element with the geometry() method:

root = Tk()
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
root.geometry("%dx%d+0+0" % (w, h))

With winfo_width() and winfo_height() you can get the width and height or the window, and also you can bind an event handler to the <Configure> event:

def resize(event):
    print("New size is: {}x{}".format(event.width, event.height))

root.bind("<Configure>", resize)

To show maximized window with title bar use the 'zoomed' attribute

root = Tk()
root.attributes('-zoomed', True)

I've found this on other website:

    import Tkinter

    MyRoot = Tkinter.Tk()
    MyRoot.state("zoomed")

    MyRoot.mainloop()

This solved my problem.


The first approach is to use the root.state('zoomed'), but is not supposed to be universally available. It works on Windows, and on my Ubuntu machine. However, under my Arch machine it doesn't.


The second is to first get the maxsize, and then set geometry manually, like:

m = root.maxsize()
root.geometry('{}x{}+0+0'.format(*m))

This works on most machines, but not on all. For example, under my Arch the maxsize() returns (1425, 870), while the real geometry of maximized window should be (1440, 848). So, you also couldn't rely on it.


And the third, in my opinion the best approach is to use root.wm_attributes('-zoomed', 1). It is universally available and seems to be the safest. On some machines in could zoom only by width or by height, but comparing to previous method, this one would never give you a window partly ouside of the screen.

Finally, if you want a fullscreen, not just zoomed window, use root.wm_attributes('-fullscreen', 1). It provides a native link to window manager's behavior, thus working much better, than playing with overrideredirect and setting geometry by hand (which on some platforms could lead to unmanaged window, which could be closed only by its own interface or killing the process, won't show on the taskbar, etc...)