python123外汇兑换计算器_python 简易计算器

python 简单使用图形界面

1.[文件] cal.py ~ 2KB 下载(292)

#-*- coding:UTF-8-*-

#Simple Cal

#######################

from Tkinter import *

def frame(root, side):

w = Frame(root)

w.pack(side=side, expand=YES, fill=BOTH)

return w

#end of def

def button(root, side, text, command=None):

w = Button(root, text=text, command=command)

w.pack(side=side, expand=YES, fill=BOTH)

return w

#end of def

class Calculator(Frame):

def __init__(self):

Frame.__init__(self)

#self.oprion_add('*Font', 'Verdana 12 bold')

self.option_add('*Font', 'Verdana 12 bold')

self.pack(expand=YES, fill=BOTH)

self.master.title('Simple Cal')

self.master.iconname('calc1')

display = StringVar()

Entry(self, relief=SUNKEN, textvariable=display).pack(side=TOP, expand=YES, fill=BOTH)

for key in ('123', '456', '789', '+0.'):

keyF = frame(self, TOP)

for char in key:

button(keyF, LEFT, char, lambda w=display, c=char: w.set(w.get() + c))

#end of for

opsF = frame(self, TOP)

for char in '-*/=':

if char == '=':

btn = button(opsF, LEFT, char)

btn.bind('', lambda e, s=self, w=display: s.calc(w), '+')

else:

btn = button(opsF, LEFT, char, lambda w=display, s='%s '%char: w.set(w.get() + s))

#end of if

#end of for

clearF = frame(self, BOTTOM)

button(clearF, LEFT, 'Clr', lambda w=display: w.set(''))

#end of def

def calc(self, display):

try:

display.set(eval(display.get()))

except:

display.set('ERROR')

#end of try and except

#end of def

#end of class

if __name__ == '__main__':

Calculator().mainloop()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值