当前仓库属于关闭状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 0

糖小二/python计算器
关闭

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
计算器.py 3.84 KB
一键复制 编辑 原始数据 按行查看 历史
糖小二 提交于 2018-10-23 16:48 +08:00 . Upload 计算器.py
#coding:utf-8
##top = Tkinter.Tk()
##label = Tkinter.Label(top,text="hello word")
##label.pack()
##button = Tkinter.Button(top,text="Hello Word!",command=exit)
##button.pack()
##
##Tkinter.mainloop()
## row (行) column(列)
from __future__ import division ##除法计算
from Tkinter import *
import math
root = Tk(className='JSQ')
ab = LabelFrame(root,padx=10,pady=10)
ab.grid(row=0,column=0,rowspan=10,columnspan=10)
ab.pack()
entry = Entry(ab)
entry.grid(row=0,column=0,columnspan=5)
def showText(event):
e = event.widget['text']
entry.insert(20000,e)
####entry.pack()
##def one():
## entry.insert(200,"1")
one = Button(ab)
one['text']='1'
one.bind('<Button-1>',func=showText)
one.grid(row=3,column=0,sticky = W+E+N+S)
##one.pack()
two = Button(ab)
two['text'] = '2'
two.bind('<Button-1>',func=showText)
two.grid(row=3,column=1,sticky = W+E+N+S)
#two.pack()
three = Button(ab)
three['text'] = '3'
three.bind('<Button-1>',func=showText)
three.grid(row=3,column=2,sticky = W+E+N+S)
#three.pack()
four = Button(ab)
four['text'] = '4'
four.bind('<Button-1>',func=showText)
four.grid(row=2,column=0,sticky = W+E+N+S)
#four.pack()
five = Button(ab)
five['text'] = '5'
five.bind('<Button-1>',func=showText)
five.grid(row=2,column=1,sticky = W+E+N+S)
#five.pack()
six = Button(ab)
six['text'] = '6'
six.bind('<Button-1>',func=showText)
six.grid(row=2,column=2,sticky = W+E+N+S)
seven = Button(ab)
seven['text'] = '7'
seven.bind('<Button-1>',func=showText)
seven.grid(row=1,column=0,sticky = W+E+N+S)
eight = Button(ab)
eight['text'] = '8'
eight.bind('<Button-1>',func=showText)
eight.grid(row=1,column=1,sticky = W+E+N+S)
nine = Button(ab)
nine['text'] = '9'
nine.bind('<Button-1>',func=showText)
nine.grid(row=1,column=2,sticky = W+E+N+S)
zero = Button(ab)
zero['text'] = '0'
zero.bind('<Button-1>',func=showText)
zero.grid(row=4,column=0,sticky = W+E+N+S)
dian = Button(ab)
dian['text'] = '.'
dian.bind('<Button-1>',func=showText)
dian.grid(row=4,column=1,sticky = W+E+N+S)
chu = Button(ab)
chu['text'] = '/'
chu.bind('<Button-1>',func=showText)
chu.grid(row=1,column=3,sticky = W+E+N+S)
cheng = Button(ab)
cheng['text'] = '*'
cheng.bind('<Button-1>',func=showText)
cheng.grid(row=2,column=3,sticky = W+E+N+S)
jian = Button(ab)
jian['text'] = '-'
jian.bind('<Button-1>',func=showText)
jian.grid(row=3,column=3,sticky = W+E+N+S)
jia = Button(ab)
jia['text'] = '+'
jia.bind('<Button-1>',func=showText)
jia.grid(row=4,column=3,sticky = W+E+N+S)
baifenhao = Button(ab)
baifenhao['text'] = '%'
baifenhao.bind('<Button-1>',func=showText)
baifenhao.grid(row=1,column=4,sticky = W+E+N+S)
fenshu = Button(ab)
fenshu['text'] = '1/x'
fenshu.bind('<Button-1>',func=showText)
fenshu.grid(row=2,column=4,sticky = W+E+N+S)
def fuhao():
entry.insert(0,'-')
zhengfu = Button(ab,command = fuhao)
zhengfu['text'] = '±'
zhengfu.grid(row=5,column=3,sticky = W+E+N+S)
def genhao():
d = entry.get()
result = eval(d)
s = math.sqrt(int(d))
entry.delete(0,END)
entry.insert(20000,s)
genhao = Button(ab,command = genhao)
genhao['text'] = '√'
genhao.grid(row=3,column=4,sticky = W+E+N+S)
def qingchu():
gh = entry.get()
entry.delete(len(gh)-1,END)
qingchu = Button(ab,command = qingchu)
qingchu['text'] = '<-'
qingchu.grid(row=5,column=0,columnspan=3,sticky = W+E+N+S)
def clear_entry ():
entry.delete(0,END)
c = Button(ab,command = clear_entry)
c['text'] = 'c'
c.grid(row=4,column=2,sticky = W+E+N+S)
def calculate():
d = entry.get()
result = eval(d)
entry.delete(0,END)
entry.insert(20000,result)
denghao = Button(ab,command = calculate)
denghao['text'] = '='
denghao.grid(row=4,column=4,rowspan=2,sticky = W+E+N+S)
root.mainloop()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/tanglibo/python_calculator.git
git@gitee.com:tanglibo/python_calculator.git
tanglibo
python_calculator
python计算器
master

搜索帮助