tkinter python maximize window

前端 未结 7 1744
情书的邮戳
情书的邮戳 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:23

    The most pythonic is" root.wm_state('zoomed'), as mentioned by @J.F.Sebastian

    0 讨论(0)
  • 2020-12-01 09:24

    I've found this on other website:

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

    This solved my problem.

    0 讨论(0)
  • 2020-12-01 09:25

    With TkAgg as backend this is the only combination that maximized the window without fullscreen:

    win_manager = plt.get_current_fig_manager()
    win_manager.window.state('zoomed')
    win_manager.full_screen_toggle()
    
    0 讨论(0)
  • 2020-12-01 09:27

    You can do it by calling

    root.state('zoomed')
    
    0 讨论(0)
  • 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...)

    0 讨论(0)
  • 2020-12-01 09:43

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

    root = Tk()
    root.attributes('-zoomed', True)
    
    0 讨论(0)
提交回复
热议问题