用户:
超厉害的老吴查看:0 回复:0 评论:0 创建时间:2023-11-01T21:11:02
【作品展示】

【作品介绍】
小学生最想要的简易计算器
【作品源代码】
from tkinter import *
root = Tk()
root.geometry("400x520")
root.title("电子计算机")
ft = ("华文琥珀", 20)
Label(root, text = "计算:", font = ft).place(x = 20, y = 20)
Label(root, text = "结果:", font = ft).place(x = 20, y = 70)
la1 = Label(root, text = "", font = ft)
la1.place(x = 100, y = 20)
la2 = Label(root, text = "0", font = ft)
la2.place(x = 100, y = 70)
def onclick(t):
if t == "清除":
la1["text"] = ""
la2["text"] = "0"
elif t == "=":
a = la1["text"]
la2["text"] = str(eval(a))
else:
la1["text"] = la1["text"] + t
def makeButton(t, x, y):
bu = Button(root, text = t, font = ft, command = lambda:onclick(t))
bu.place(x = x, y = y, width = 100, height = 100)
arr = []
arr.extend(["0", "清除", "=", "+"])
arr.extend(["1", "2", "3", "-"])
arr.extend(["4", "5", "6", "*"])
arr.extend(["7", "8", "9", "/"])
count = 0
for a in range(4):
y = 120 + 100 * a
for b in range(4):
x = b * 100
t = arr[count]
makeButton(t, x, y)
count += 1
mainloop()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn