import tkinter as tk
root = tk.Tk()
arr = [('MC','M+','M-','MR'),('C','±','/','*'),(7,8,9,'-'),(4,5,6,'+'),(1,2,3,'='),(0,'.')]
tk.Entry(root).grid(row=0,columnspan=4,ipadx=3,sticky=tk.NSEW)
for rindex,r in enumerate(arr):
for cindex,c in enumerate(r):
if c == '=':
tk.Button(root, text=c, width=6).grid(row=rindex + 1,column=cindex,rowspan=2,sticky=tk.NSEW)
elif c == '.':
tk.Button(root, text=c, width=6).grid(row=rindex + 1, column=cindex, columnspan=2,sticky=tk.NSEW)
else:
tk.Button(root,text=c,width=6).grid(row=rindex+1,column=cindex,sticky=tk.NSEW)
root.geometry('215x210')
root.mainloop()
GUI初学-计算器界面
最新推荐文章于 2023-06-18 16:21:25 发布