计算器 UI 界面设计
from tkinter import *class Calculator(Frame):def __init__(self,master=None):super().__init__(master)self.master = masterself.pack()self.createWidget()def createWidget(self):"计算器UI界面创建"j = 0k = 1btn_list = ["MC", "M+", "M-", "MR","C", "±", "/", "*",7, 8, 9, "-",4, 5, 6, "+",1, 2, 3, "=",0, "."]Entry(self).grid(row=0, column=0, columnspan=4, sticky=NSEW)for i in btn_list:j += 1if i == "=":Button(self, text="{0}".format(i)).grid(row=k, column=j-1, rowspan=2, sticky=NSEW)elif i == 0:Button(self, text="{0}".format(i)).grid(row=k, column=j-1, columnspan=2, sticky=EW)elif i ==".":Button(self, text="{0}".format(i)).grid(row=k, column=j, sticky=EW)else:Button(self, text="{0}".format(i)).grid(row=k, column=j-1, sticky=EW)if j == 4:k += 1j = 0if __name__=='__main__':root = Tk()root.geometry("150x200+200+200")calculate = Calculator(master=root)root.mainloop()