Skip to main content
 首页 » 编程设计

python之添加按钮时 tk 窗口变小

2025年02月15日13xing901022

<分区>

当我用一个什么都不做的按钮键入一个简单的 hello world gui 时,tk 窗口不会执行我想要的操作。我希望窗口保持 500 x 500,同时左上角有一个小按钮。这是我当前的简单代码:

from tkinter import * 
window = Tk() 
window.config(height = 500, width = 500) #the window initialize as a 500px x 500px window 
button = Button(window, text = 'hello world')   
button.pack() #but when I added a button, the window shinks to the size of the button 
window.mainloop()  

我正在使用 Python 3.6 运行 Mac Sierra。并按照手册的说明下载了一个外部 tkl。

Srcreenshot