資源簡介
使用python tkinter制作計算器源代碼,自己思考邏輯,借鑒了一些大神的思路,寫了一個不是很完善的計算器
代碼片段和文件信息
from?tkinter?import?*
def?frame(root?side):
????w?=?frame(root)
????w.pack(side=side?expand=YES?fill=BOTH)
????return?w
def?button(root?side?text?command=None):
????w?=?Button(root?text=text?command=command)
????w.pack(side=side?expand=YES?fill=BOTH)
????return?w
class?Calculator(frame):
????def?__init__(self):
????????frame.__init__(self)
????????self.option_add(‘*Font‘?‘Verdana?12?bold‘)
????????self.pack(expand=YES?fill=BOTH)
????????self.master.title(‘Simple?Calculator‘)
????????self.master.iconname(“calc1“)
????????display?=?StringVar()
????????Entry(self?relief=SUNKENtextvariable=display).pack(side=TOP?expand=YESfill=BOTH)
????????for?key?in?(“123“?“456“?“789“?“-0.“):
????????????keyF?=?frame(self?TOP)
????????????for?char?in?key:
??????????
評論
共有 條評論