'How can I make a Tkinter application utilise all screen space?

I'm trying to find a way to make a Tkinter application's main window utilise all screen space. I have to always maximise the screen after the app starts. I have tried this code:

win.state('zoomed')

However, it's not supported on Linux. I need a solution that will work on any platform.



Solution 1:[1]

There's lots of information in the answers to this question, but there are issues on different systems with each:

Basically, there doesn't appear to be any single cross-platform solution to this. So what I suggest is that you use a try/except block, and if one solution fails, use the other:

import tkinter

root = tkinter.Tk()
try:
    root.wm_attributes("-zoomed", True)
except tkinter.TclError:
    root.state('zoomed')
root.mainloop()

An alternative for those who don't like try/except blocks is to use the built-in platform module, and some if statements:

import tkinter, platform

root = tkinter.Tk()
if platform.uname()[0] == "Windows":
    root.state('zoomed')
else:
    root.wm_attributes("-zoomed", True)
root.mainloop()

I'm 99% sure this works on Windows, but as I don't have access to a Windows for testing, it'd be nice to have have someone confirm that it works on Windows. Hope this helps, and let me know if you have any questions!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sylvester Kruin