from tkinter import *
class Application(Frame):
def __init__(self,master=None):
super().__init__(master)
self.master = master
self.pack()
self.createWight()
def createWight(self):
btnTEXT = (("MC", "M+", "M-", "MR"),
("C", "±", "/", "*"),
(7,8,9,"-"),
(4,5,6,"+"),
(0,1,2,"="),
(0,"."))
Entry(self).grid(row=0,column=0, columnspan=4,pady=10)
for rindex,r in enumerate(btnTEXT):
for cindex,c in enumerate(r):
if c == "=":
Button(self,text=c,width=2).grid(row=1+rindex,column=cindex, rowspan=2,sticky=NSEW)
elif c == "0":
Button(self,text=c,width=2).grid(row=1+rindex,column=cindex, columnspan=2, sticky=NSEW)
elif c == ".":
Button(self,text=c,width=2).grid(row=1+rindex,column=cindex+1, sticky=NSEW)
else:
Button(self,text=c,width=2).grid(row=1+rindex,column=cindex,sticky=NSEW)
if __name__ == '__main__':
root = Tk()
root.title("计算器")
root.geometry("300x300+200+300")
app = Application(master=root)
root.mainloop()
老师,和您的一样,0为啥没有跨列
