收银台python tkinter
时间: 2023-12-15 10:33:04 浏览: 168
以下是一个简单的收银台Python tkinter的例子:
```python
import tkinter as tk
class Cashier:
def __init__(self, master):
self.master = master
master.title("收银员1.1")
master.geometry("400x400")
# 创建标签和输入框
self.label1 = tk.Label(master, text="商品名称")
self.label1.pack()
self.entry1 = tk.Entry(master)
self.entry1.pack()
self.label2 = tk.Label(master, text="商品价格")
self.label2.pack()
self.entry2 = tk.Entry(master)
self.entry2.pack()
self.label3 = tk.Label(master, text="数量")
self.label3.pack()
self.entry3 = tk.Entry(master)
self.entry3.pack()
# 创建按钮
self.button = tk.Button(master, text="计算总价", command=self.calculate)
self.button.pack()
self.total_label = tk.Label(master, text="")
self.total_label.pack()
def calculate(self):
# 获取输入框的值
name = self.entry1.get()
price = float(self.entry2.get())
quantity = int(self.entry3.get())
# 计算总价
total = price * quantity
# 显示总价
self.total_label.config(text=f"{name}的总价为{total}元")
root = tk.Tk()
cashier = Cashier(root)
root.mainloop()
```
这个例子创建了一个简单的收银台界面,用户可以输入商品名称、价格和数量,然后点击“计算总价”按钮,程序会计算总价并显示在界面上。
阅读全文