其他分享
首页 > 其他分享> > pyhon计算器外壳,只是躯壳,不能用于计算

pyhon计算器外壳,只是躯壳,不能用于计算

作者:互联网

代码如下:

from tkinter import *
from tkinter import messagebox

class Application(Frame):

    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.creatWidget()

    def creatWidget(self):
        """通过grid实现计算器的界面"""
        btnText = (("MC", "M+", "M-", "MR"),
                   ("C", "±", "/", "*"),
                   ("7", "8", "9", "-"),
                   ("4", "5", "6", "+"),
                   (1,2,3, "="),
                   (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=rindex + 1, column=cindex,rowspan=2, sticky=NSEW)
                elif c==0:
                    Button(self, text=c, width=2).\
                        grid(row=rindex + 1, column=cindex, columnspan=2, sticky=NSEW)
                elif c==".":
                    Button(self, text=c, width=2). \
                        grid(row=rindex + 1, column=cindex+1, sticky=NSEW)
                else:
                    Button(self,text=c,width=2).\
                    grid(row=rindex+1,column=cindex,sticky=NSEW)

if __name__ == '__main__':
    root = Tk()
    root.geometry("200x250+300+200")
    app = Application(master=root)
    root.mainloop()

 

标签:__,rindex,pyhon,self,grid,计算器,master,躯壳,row
来源: https://www.cnblogs.com/linfengpy/p/15747430.html