我想创建一个可以全屏和任何其他窗口大小播放的游戏。为此,我有代码创建一个框架、两个按钮和一个标签。我希望按钮和标签位于框架的中心,但我不知道如何做到这一点。
作为临时解决方案,我在按钮顶部放置了一个空的黑色标签,但现在这不适用于我的想法。
这是我现在拥有的代码:
import tkinter as tk
def startgame():
pass
mw = tk.Tk()
mw.title('The Game')
back=tk.Frame(master=mw, width=500, height=500, bg='black')
back.pack_propagate(0)
back.pack(fill=tk.BOTH, expand=1) #Adapts the size to the window
#Here I had the label
go = tk.Button(master=back, text='Start Game', command=startgame, bg='#111', fg='red')
go.pack()
close = tk.Button(master=back, text='Quit', command=mw.destroy, bg='#111', fg='red')
close.pack()
info = tk.Label(master=back, text='Made by me!', bg='red', fg='black')
info.pack()
mw.mainloop()
Run Code Online (Sandbox Code Playgroud)
问题:如何不断将按钮等设置在中间?