tkinter计算门票总价
时间: 2023-12-22 20:29:28 浏览: 36
以下是一个使用tkinter计算门票总价的例子:
```python
import tkinter as tk
def calculate_total_price():
adult_tickets = int(adult_entry.get())
child_tickets = int(child_entry.get())
adult_price = 50
child_price = 30
total_price = (adult_tickets * adult_price) + (child_tickets * child_price)
total_label.config(text="总价:{} 元".format(total_price))
root = tk.Tk()
root.title("门票计算器")
# 创建标签和输入框
adult_label = tk.Label(root, text="成人票数量:")
adult_label.pack()
adult_entry = tk.Entry(root)
adult_entry.pack()
child_label = tk.Label(root, text="儿童票数量:")
child_label.pack()
child_entry = tk.Entry(root)
child_entry.pack()
# 创建计算按钮
calculate_button = tk.Button(root, text="计算总价", command=calculate_total_price)
calculate_button.pack()
# 创建显示总价的标签
total_label = tk.Label(root, text="总价:")
total_label.pack()
root.mainloop()
```