python完整代码,计算器,gui界面
时间: 2023-01-31 13:05:08 浏览: 112
python GUI模拟实现计算器
这是一个用 Python 实现的简单计算器 GUI 程序的示例代码:
```python
import tkinter as tk
class Calculator(tk.Tk):
def __init__(self):
super().__init__()
self.create_widgets()
def create_widgets(self):
# 创建输入框
self.input_text = tk.StringVar()
self.input_entry = tk.Entry(self, textvariable=self.input_text)
self.input_entry.pack()
# 创建按钮
self.button1 = tk.Button(self, text="1", command=lambda: self.update_input("1"))
self.button1.pack()
self.button2 = tk.Button(self, text="2", command=lambda: self.update_input("2"))
self.button2.pack()
self.button3 = tk.Button(self, text="3", command=lambda: self.update_input("3"))
self.button3.pack()
self.button4 = tk.Button(self, text="4", command=lambda: self.update_input("4"))
self.button4.pack()
self.button5 = tk.Button(self, text="5", command=lambda: self.update_input("5"))
self.button5.pack()
self.button6 = tk.Button(self, text="6", command=lambda: self.update_input("6"))
self.button6.pack()
self.button7 = tk.Button(self, text="7", command=lambda: self.update_input("7"))
self.button7.pack()
self.button8 = tk.Button(self, text="8", command=lambda: self.update_input("8"))
self.button8.pack()
self.button9 = tk.Button(self, text="9", command=lambda: self.update_input("9"))
self.button9.pack()
self.button0 = tk.Button(self, text="0", command=lambda: self.update_input("0"))
self.button0.pack()
self.button_add = tk.Button(self, text="+", command=lambda: self.update_input("+"))
self.button_add.pack()
self.button_subtract = tk.Button(self, text="-", command=lambda: self.update_input("-"))
self.button_subtract.pack()
self.button_multiply = tk.Button(self, text="*", command=lambda: self.update_input("*"))
self.button_multiply.pack()
self.button_divide = tk.Button(self, text="/", command=lambda: self.update_input("/"))
self.button_divide.pack()
self.button_equals = tk.Button(self
阅读全文