我正在尝试将“是”和“否”按钮的位置降低。如果我将row =
设置为不同的数字,则可以工作,但是每次我将row =
都设置为相同的数字时,只会使它们回到原来的位置。有人可以解释为什么会这样吗?
图片
NO.grid(row = 3, column = 5)
,YES.grid(row = 3, column = 7)
NO.grid(row = 9, column = 5)
, YES.grid(row = 10, column = 7)
NO.grid(row = 10, column = 7)
, YES.grid(row = 10, column = 7)
#Intro
l = Label(win, text = "Welcome to a simple number game.\n Would you like to play?", font=('Snap ITC', 30), bg='yellow', fg='slateblue')
l.grid(row = 2, column = 5, columnspan=5)
#Play or not buttons(YES/NO)
NO = Button(win, text = 'NO', command=clicked, relief=RAISED, padx=30, pady=1 )
NO.config(bg='DodgerBlue2', fg='spring green', font=('Snap ITC', 10), bd=6)
NO.grid(row = 10, column = 5)
YES = Button(win, text = 'YES', command=clicked1, relief=RAISED, padx=30, pady=1)
YES.config(bg='DodgerBlue2', fg='spring green', font=('Snap ITC', 10), bd=6)
YES.grid(row = 10, column = 7)
答案 0 :(得分:1)
网格几何管理器认为不包含任何内容的行的大小为零。但是您可以使用填充来创建距离:
NO.grid(row = 10, column = 5, pady=(20,0))
填充指定您要在行顶部和小部件之间有多少像素。在这种情况下,我指定了pady=(20,0)
,这意味着顶部20像素,底部0像素。如果您想在顶部和底部使用相同的金额,可以写pady=20