<p>通过设置<code>pack_propagate(0)</code>,可以关闭<code>pack_propagate</code></p>
<p>关闭<code>pack_propagate</code>这里基本上是说不要让框架内的小部件控制它的大小。所以你把它的宽度和高度设为500。关闭propagate stills允许它是这样的大小,而小部件不改变框架的大小来填充它们各自的宽度/高度,这是正常情况下会发生的事情</p>
<p>要关闭调整根窗口的大小,可以设置<code>root.resizable(0, 0)</code>,其中在<code>x</code>和<code>y</code>方向上分别允许调整大小。</p>
<p>要将maxsize设置为window,如另一个答案中所述,您可以设置<code>maxsize</code>属性或<code>minsize</code>,尽管您只需设置根窗口的几何体,然后关闭大小调整。更灵活一点</p>
<p>当您在小部件上设置<code>grid</code>或<code>pack</code>时,它将返回<code>None</code>。因此,如果您希望能够保留对widget对象的引用,那么不应该将variabe设置为要在其上调用<code>grid</code>或<code>pack</code>的widget。相反,您应该将变量设置为小部件<code>Widget(master, ....)</code>,然后改为调用小部件上的<code>pack</code>或<code>grid</code>。</p>
<pre><code>import tkinter as tk
def startgame():
pass
mw = tk.Tk()
#If you have a large number of widgets, like it looks like you will for your
#game you can specify the attributes for all widgets simply like this.
mw.option_add("*Button.Background", "black")
mw.option_add("*Button.Foreground", "red")
mw.title('The game')
#You can set the geometry attribute to change the root windows size
mw.geometry("500x500") #You want the size of the app to be 500x500
mw.resizable(0, 0) #Don't allow resizing in the x or y direction
back = tk.Frame(master=mw,bg='black')
back.pack_propagate(0) #Don't allow the widgets inside to determine the frame's width / height
back.pack(fill=tk.BOTH, expand=1) #Expand the frame to fill the root window
#Changed variables so you don't have these set to None from .pack()
go = tk.Button(master=back, text='Start Game', command=startgame)
go.pack()
close = tk.Button(master=back, text='Quit', command=mw.destroy)
close.pack()
info = tk.Label(master=back, text='Made by me!', bg='red', fg='black')
info.pack()
mw.mainloop()
</code></pre>