【发布时间】:2016-08-04 06:58:04
【问题描述】:
我想创建一个可以全屏和任何其他窗口大小玩的游戏。为此,我有代码创建一个框架、两个按钮和一个标签。我希望按钮和标签位于框架的中心,但我不知道该怎么做。
作为临时解决方案,我在按钮顶部放置了一个空的黑色标签,但现在这不符合我的想法。
这是我现在拥有的代码:
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()
问题:如何将按钮等设置在中间?
【问题讨论】:
-
你应该可以使用 .pack(anchor=CENTER)
-
那行不通。我将它放入按钮和标签中,但它不起作用。我错过了什么吗?
标签: python python-3.x tkinter