From 2afae1c7d3b2f2a53d5fbaa970716370d8d2b2a5 Mon Sep 17 00:00:00 2001 From: pjf4ocuvn <2017614493@qq.com> Date: Fri, 31 May 2024 15:51:12 +0800 Subject: [PATCH] ADD file via upload --- fruit.py | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 fruit.py diff --git a/fruit.py b/fruit.py new file mode 100644 index 0000000..d193b0d --- /dev/null +++ b/fruit.py @@ -0,0 +1,110 @@ +import tkinter as tk +from tkinter import ttk + +win = tk.Tk() +win['bg'] = '#BDBDBD' +win.title('超市') +win.geometry('775x750+400+20') + +tk.Label(win, text='水果超市\n--------------------------------', width=30, fg='orange', bg='#00FFFF', font=('Arial', 20)).pack() + +# 水果名字 +fruit_name = ['西瓜', '苹果', '香蕉', '榴莲', '脐橙', '红枣', '芒果', '哈密瓜'] +# 水果价格 +fruit_price = [10, 20, 12, 50, 13, 14, 20, 9] + + +# 序号 +xu_hao = [1, 2, 3, 4, 5, 6, 7, 8] +# 你的钱 +tk.Label(win, text='你有多少钱').place(x=540, y=100) +# 你的钱输出框 +Money = tk.Entry(win, bd=5, width=10) +Money.place(x=620, y=97) + +# 序号 +tk.Label(win, text='序号').place(x=540, y=180) +# 序号输入框 +ent_xuhao = tk.Entry(win, bd=5, width=10) +ent_xuhao.place(x=620, y=177) + +# 数量 +tk.Label(win, text='数量').place(x=540, y=220) +# 数量输入框 +ent_quantity = tk.Entry(win, bd=5, width=10) +ent_quantity.place(x=620, y=217) + + +# 购物车输出框 +txt_Text = tk.Text(win, bg='#585858', fg='#F7FE2E', width=63,height=20, bd=8) +txt_Text.place(x=20, y=410) + +# 创建表格 +table_head = ('fruit name', 'fruit price', 'xu_hao') +table_main = ttk.Treeview(win, height=8, show='headings', columns=table_head) + +# 设置表头 +table_main.heading('fruit name', text='水果名字') +table_main.heading('fruit price', text='水果价格(美元)') +table_main.heading('xu_hao', text='序号') +# 设置位置 +table_main.place(x=20, y=80) +# 设置文字对齐 +table_main.column('fruit name', width=200, anchor='center') +table_main.column('fruit price', width=200, anchor='center') +table_main.column('xu_hao', width=60, anchor='center') + +str_name = '你要购买的水果' +str_price = '你需要支付的金额' +str_rest = '你剩余的金额为' + + +# 查看水果函数 +def table(): + for i in range(len(fruit_price)): + table_main.insert('', i, values=(fruit_name[i], fruit_price[i], xu_hao[i])) + +#语句 + + +# sql = "insert into user(name, password) values ('%s', '%s')" % (user_name, user_password) + + +def main(): + # global str_name, str_price + quantity = int(ent_quantity.get()) + xuhao = int(ent_xuhao.get()) + money = int(Money.get()) + + if xuhao < 1 or xuhao > 8: + tk.Label(win, text='输入有误,请输入1-8之间的序号').place(x=540, y=260) + Total_price = quantity*fruit_price[xuhao-1] + if money < Total_price: + tk.Label(win, text='大人钱不够!\n请你点击 ''退出'' 退出程序!!', width=20, height=10, font=('Arial', 30), bg='black', fg='red').place(x=40, y=100) + butt_close = tk.Button(win, text='退出', bd=10, width=15, height=3, command=close) + butt_close.place(x=200, y=450) + else: + txt_Text.insert('end', str_name.ljust(20, '-') + str(fruit_name[xuhao - 1]) + '\n') + txt_Text.insert('end', str_price.ljust(19, '-') + str(Total_price) + '(美元)' + '\n') + txt_Text.insert('end', str_rest.ljust(20, '-')+str(money-Total_price)+'(美元)'+'\n') + txt_Text.insert('end', '欢迎下次光临!') + + +def close(): + + win.destroy() + + +# 展示水果按钮 +butt_table = tk.Button(win, text='查看水果', height=2, font=("Arial", 12), width=20, bg='black', fg='pink', command=table) +butt_table.place(x=160, y=280) +# 结算按钮 +butt_main = tk.Button(win, text='结算', height=2, font=("Arial", 12), width=20, bg='black', fg='orange', command=main) +butt_main.place(x=540, y=450) + +# 购物车标题 +tk.Label(win, text='购物车\n-----------------------------------', font=('Arial', 15), bg='lightgreen', fg='yellow').place(x=130, y=350) + + +win.mainloop() +