用户:编码已破译查看:3 回复:1 评论:3 创建时间:2021-08-17T19:30:03
import tkinter as tk
import time
import tkinter.messagebox as box
from math import *
root = tk.Tk()
root.title('模拟计算机')
root.geometry('330x390')
var_value = tk.StringVar()
var_count = tk.StringVar()
var_value.set('0')
def click(value = ''):
try:
entry_value.insert('insert',str(value))
except:
pass
def count():
try:
if entry_value.get() == '':
var_value.set('0')
else:
var_value.set(str(eval(entry_value.get())))
except:
box.showerror(title = '错误提示',message = '表达式错误')
def delete():
try:
var_count.set(var_count.get()[0:-1])
except:
pass
def clean(mode = 'end'):
try:
entry_value.delete(0,'end')
except:
pass
entry_value = tk.Entry(root,textvariable = var_count,bd = 4,width = 20,font = ('Arial',20))
label_value = tk.Label(root,textvariable = var_value,font = ('Arial',20))
#第一行(x = 0,y = 90)
tk.Button(root,text = 'C',font = ('Arial',20),width = 3,height = 1,command = clean).place(x = 0,y = 90)
tk.Button(root,text = '⇦',font = ('Arial',20),width = 3,height = 1,command = delete).place(x = 60,y = 90)
tk.Button(root,text = 'π',font = ('Arial',20),width = 3,height = 1,command = lambda:click('(pi)')).place(x = 120,y = 90)
tk.Button(root,text = 'e',font = ('Arial',20),width = 3,height = 1,command = lambda:click('(e)')).place(x = 180,y = 90)
#第二行(x = 0,y = 150)
tk.Button(root,text = '7',font = ('Arial',20),width = 3,height = 1,command = lambda:click('7')).place(x = 0,y = 150)
tk.Button(root,text = '8',font = ('Arial',20),width = 3,height = 1,command = lambda:click('8')).place(x = 60,y = 150)
tk.Button(root,text = '9',font = ('Arial',20),width = 3,height = 1,command = lambda:click('9')).place(x = 120,y = 150)
tk.Button(root,text = '+',font = ('Arial',20),width = 3,height = 1,command = lambda:click('+')).place(x = 210,y = 150)
tk.Button(root,text = '^',font = ('Arial',20),width = 3,height = 1,command = lambda:click('**')).place(x = 270,y = 150)
#第三行(x = 0,y = 210)
tk.Button(root,text = '4',font = ('Arial',20),width = 3,height = 1,command = lambda:click('4')).place(x = 0,y = 210)
tk.Button(root,text = '5',font = ('Arial',20),width = 3,height = 1,command = lambda:click('5')).place(x = 60,y = 210)
tk.Button(root,text = '6',font = ('Arial',20),width = 3,height = 1,command = lambda:click('6')).place(x = 120,y = 210)
tk.Button(root,text = '-',font = ('Arial',20),width = 3,height = 1,command = lambda:click('-')).place(x = 210,y = 210)
tk.Button(root,text = '%',font = ('Arial',20),width = 3,height = 1,command = lambda:click('%')).place(x = 270,y = 210)
#第四行(x = 0,y = 270)
tk.Button(root,text = '1',font = ('Arial',20),width = 3,height = 1,command = lambda:click('1')).place(x = 0,y = 270)
tk.Button(root,text = '2',font = ('Arial',20),width = 3,height = 1,command = lambda:click('2')).place(x = 60,y = 270)
tk.Button(root,text = '3',font = ('Arial',20),width = 3,height = 1,command = lambda:click('3')).place(x = 120,y = 270)
tk.Button(root,text = '×',font = ('Arial',20),width = 3,height = 1,command = lambda:click('*')).place(x = 210,y = 270)
tk.Button(root,text = '()',font = ('Arial',20),width = 3,height = 1,command = lambda:click('()')).place(x = 270,y = 270)
#第五行(x = 0,y = 330)
tk.Button(root,text = '00',font = ('Arial',20),width = 3,height = 1,command = lambda:click('00')).place(x = 0,y = 330)
tk.Button(root,text = '0',font = ('Arial',20),width = 3,height = 1,command = lambda:click('0')).place(x = 60,y = 330)
tk.Button(root,text = '.',font = ('Arial',20),width = 3,height = 1,command = lambda:click('.')).place(x = 120,y = 330)
tk.Button(root,text = '÷',font = ('Arial',20),width = 3,height = 1,command = lambda:click('/')).place(x = 210,y = 330)
tk.Button(root,text = '=',font = ('Arial',20),width = 3,height = 1,command = count).place(x = 270,y = 330)
entry_value.pack()
label_value.pack()
root.mainloop()
夜明逢生额。。。你做这个给我们看,应该是想炫耀或想要个点评吧,额。。。那我就给你个点评吧!可能是这个作品的唯一点评,我的论坛里没几个人点评我的python作品,额。。。点评该怎么说呢。。。额。。。十分的好。。。额。。。我不怎么会点评作品,额。。。那就这样了,加油哦!
点赞0
评论