这将是一个简单的计算器,但我想制作一个“0”按钮,它需要 2 列(0 和 1)。我应该怎么办?我已经尝试过 colmunspan 但它不起作用......我不想使用“空按钮”。
# -*- coding: utf-8 -*-
from Tkinter import Tk, W, E
from ttk import Frame, Button, Label, Entry, Style
#=========================================================================#
class Calc(Frame):
def __init__(self,main):
Frame.__init__(self, main)
self.main = main
self.initUI()
def initUI(self):
self.main.title('Calculator by MM')
Style().configure("TButton", padding= (0,5,0,5), background = 'black',foreground = 'blue')
self.rowconfigure(0, pad = 3)
self.rowconfigure(1, pad = 3)
self.rowconfigure(2, pad = 3)
self.rowconfigure(3, pad = 3)
self.rowconfigure(4, pad = 3)
self.columnconfigure(0,pad =3)
self.columnconfigure(1,pad =3)
self.columnconfigure(2,pad =3)
self.columnconfigure(3,pad =3)
e = Entry(self,justify = 'right')
e.grid(row = 0, columnspan = 5, sticky = E + W)
cof = Button(self, text = 'Back')
cof.grid(row = 1,column = 0)
clr = Button(self, text = 'C')
clr.grid(row = 1,column = 1)
neg = Button(self, text = '±')
neg.grid(row = 1,column = 2)
proc = Button(self, text = '%')
proc.grid(row = 1,column = 3)
pierw = Button(self, text = '√')
pierw.grid(row = 1, column = 4)
sied = Button(self,text = '7')
sied.grid(row = 2,column = 0)
os = Button(self,text = '8')
os.grid(row = 2,column =1)
dziew = Button(self,text = '9')
dziew.grid(row = 2, column =2)
dziel = Button(self,text = '/')
dziel.grid(row = 2,column = 3)
kw = Button(self, text = 'x^2')
kw.grid(row = 2,column = 4)
czt = Button(self,text = '4')
czt.grid(row = 3,column = 0)
pie = Button(self,text = '5')
pie.grid(row = 3,column = 1)
sze = Button(self,text = '6')
sze.grid(row = 3,column = 2)
jed = Button(self, text = '1')
jed.grid(row = 4,column = 0)
dwa = Button(self,text = '2')
dwa.grid(row = 4, column = 1)
trzy = Button(self, text = '3')
trzy.grid(row = 4,column =2)
zer = Button(self,text = '0')
zer.grid(row = 5,column = 1)
krop = Button(self,text = '.')
krop.grid(row = 5,column = 2 )
self.pack()
def run(self):
self.main.mainloop()
Calc(Tk()).run()