【问题标题】:Set the size of main window设置主窗口大小
【发布时间】:2014-05-22 01:29:44
【问题描述】:

我想设置预定义的窗口大小。示例应用:

from tkinter import *

root = Tk()
button = Button(root, text="Example button")
button.pack()

root.mainloop()

生成的窗口非常小。它和按钮一样大。如何让窗口变大?

【问题讨论】:

    标签: python tkinter


    【解决方案1】:

    你可以使用几何。

    from tkinter import *
    
    root = Tk()
    button = Button(root, text="Example button")
    button.pack()
    
    root.geometry("200x200")
    
    root.mainloop()
    

    【讨论】:

      【解决方案2】:

      你可以使用tkinter.Tk.geometry方法:

      from tkinter import *
      
      root = Tk()
      root.geometry("500x500")  # Set the window's size to 500 by 500 pixels
      
      button = Button(root, text="Example button")
      button.pack()
      
      root.mainloop()
      

      【讨论】:

        猜你喜欢
        • 2013-10-05
        • 2013-09-09
        • 1970-01-01
        • 2022-07-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-18
        相关资源
        最近更新 更多