
使用Python创建简易GUI计算器
5星
- 浏览量: 0
- 大小:None
- 文件类型:None
简介:
本教程将指导您利用Python编程语言及Tkinter库构建一个功能简单的图形用户界面(GUI)计算器。通过一系列简洁明了的操作步骤,帮助初学者掌握基础的GUI应用程序开发技巧。
运行效果:完整代码
```python
from tkinter import *
def click(num):
global op
op = op + str(num)
iptext.set(op)
def evaluate():
global op
output = str(eval(op))
iptext.set(output)
def clearDisplay():
global op
op =
iptext.set(op)
calc = Tk()
calc.title(TechVidvan Calculator)
op =
iptext = StringVar()
display = Entry(calc, font=(arial, 20, bold), textvariable=iptext,
bd=30, insertwidth=4, width=14, bg=powder blue,
justify=right).grid(columnspan=4)
for i in range(10):
b = Button(calc, height=2,width=6,padx=9,pady=8,text=str(i),
command=lambda num=i: click(num)).grid(row=(i%5)+2,
column=((i-i%5)/4)%3)
bclear = Button(calc, text=Clear,height=2,width=6,command=clearDisplay).grid(row=1,column=0)
bequal = Button(calc,text==,height=2,width=6,command=evaluate).grid(row=1,column=1)
backspace = Button(calc,text=<-,height=2,width=6,command=lambda:iptext.set(iptext.get()[:-1])).grid(row=1,column=3)
```
全部评论 (0)


