tkinter python maximize window

前端 未结 7 1778
情书的邮戳
情书的邮戳 2020-12-01 08:44

I want to initialize a window as maximized, but I can\'t find out how to do it. I\'m using python 3.3 and Tkinter 8.6 on windows 7. I guess the answer is just here: http://w

7条回答
  •  悲&欢浪女
    2020-12-01 09:27

    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...)

提交回复
热议问题