简易计算器

1.代码展示

from tkinter import Tk, Label, RAISED, Button, Entry
from tkinter.messagebox import showinfo

root = Tk()

def cal():
    a = dataEnt.get()
    try:
        b = eval(a)
        showinfo(message= '结果为 {}'.format(b))
    except:
        showinfo(message= '这都能输错,你的数学是体育老师教的吗!')

a = Label(master=root, font = ('仿宋', 18 , 'bold '),
text = '简易计算器', foreground = 'black' , width=20 ,height = 2)
a.grid(row = 0,column = 1)

b = Label(master=root, font = ('仿宋', 14 , 'bold '),
text = '请输入算式:', foreground = 'red' , width=20 ,height = 2)
b.grid(row = 1,column = 0)

c = Label(master=root, font = ('仿宋', 14 , 'bold '),
text = """(注意:运算符
应为+,-,*,/)""", foreground = 'blue' , width=18 ,height = 2)
c.grid(row = 1,column = 2)

dataEnt = Entry(root, width=40)
dataEnt.grid(row = 1,column = 1)

buttom = Button(root, width=15, height=2, text = 'ENTER', command=cal)
buttom.grid(row = 2,column = 1)

root.mainloop()
 
2.代码实现

 

原文地址:https://www.cnblogs.com/wxMing/p/14100286.html