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!