tkinter python maximize window

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

    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)
    
    0 讨论(0)
提交回复
热议问题