我想把AC按钮和“0”按钮调大一些。我怎样才能做到这一点而不弄乱我的for循环?我试过columnspan,但它对我不起作用。你知道吗
buttons = [['AC' , '%', '+' ],
['7' , '8' , '9' , '-' ],
['4' , '5' , '6' , '*' ],
['1' , '2' , '3' , '/' ],
['0' , '.' , '=' ]]
for r in range(len(buttons)):
for c in range(len(buttons[r])):
def cmd(x = buttons[r][c]):
self.click(x)
b = Button(self,
text = buttons[r][c],
width = 3,
relief = RAISED,
command = cmd)
b.grid(row = r + 1, column = c)
你需要给AC和zero按钮一个2的列跨度。这对于您当前的体系结构来说有点尴尬,但您可以尝试以下方法:
不过,我可能会建议更像这样:
这有利于更明确一点,少一点黑客。你知道吗
可能有按钮名称和大小值的字典:
然后在定义要放置的大小时引用它:
您可能还需要更改b.grid()参数。你知道吗
相关问题 更多 >
编程相关推荐