我想为我的井字游戏创造一个窗口。在主根窗口(dimensions->;height=700,width=600)中,我创建了两个框架。你知道吗
1:顶部框架称为ActionArea,其尺寸为->;Height=600,width=600
2:底部框架称为StatArea,其尺寸为->;高度=100,宽度=600
在顶部框架中,我放置了9个按钮,每个按钮的大小相等,为200*200
这是代码的相关部分:
root=tk.Tk()
root.title("TIC TAC TOE")
root.geometry("600x700")
#creating two frames
ActionArea=tk.Frame(root,height=600,width=600,bg="AliceBlue")
StatArea=tk.Frame(root,height=100,width=600,bg="RoyalBlue")
#placing the frames onto root window
ActionArea.grid(row=0,column=0)
StatArea.grid(row=1,column=0)
#creating the buttons
b1=tk.Button(ActionArea,text="", height=200,width=200,bg="AliceBlue")
b2=tk.Button(ActionArea,text="", height=200,width=200,bg="AliceBlue")
b3=tk.Button(ActionArea,text="", height=200,width=200,bg="AliceBlue")
b4=tk.Button(ActionArea,text="", height=200,width=200,bg="AliceBlue")
b5=tk.Button(ActionArea,text="", height=200,width=200,bg="AliceBlue")
b6=tk.Button(ActionArea,text="", height=200,width=200,bg="AliceBlue")
b7=tk.Button(ActionArea,text="", height=200,width=200,bg="AliceBlue")
b8=tk.Button(ActionArea,text="", height=200,width=200,bg="AliceBlue")
b9=tk.Button(ActionArea,text="", height=200,width=200,bg="AliceBlue")
#packing the buttons
b1.grid(row=0,column=0)
b2.grid(row=0,column=1)
b3.grid(row=0,column=2)
b4.grid(row=1,column=0)
b5.grid(row=1,column=1)
b6.grid(row=1,column=2)
b7.grid(row=2,column=0)
b8.grid(row=2,column=1)
b9.grid(row=2,column=2)
你知道吗太多了怀疑。 我把每个纽扣的尺寸精确到200*200,以适合我的顶部框架,这个框架的尺寸是600*600。然而,正如你所看到的,按钮变得大得离谱。为什么会这样?你知道吗
这正是因为您用
height=200, width=200
调整了按钮的大小。tkinter.Button
高度和宽度并不总是以像素为单位。从documentation:您的按钮包含
text = ""
,因此大小以文本为单位,大于像素。你知道吗通常不需要显式设置每个帧的大小,特别是如果希望使它们的大小相同。看看here的例子。你知道吗
相关问题 更多 >
编程相关推荐