python--超级简单的超市水果销售系统--1.0

超级简单的超市水果销售系统--1.0


给大家带来一个简单的超市水果销售系统,功能也是相当的简单, 可以查看水果列表,可以,添加水果到购物车,以及结算。话不多少,直接上代码:

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='#DF3A01', 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()

截图:
在这里插入图片描述

是不是简单到没有朋友,因为这个版本过于简单,所以后面制作了水果2.0,下期见。

  • 5
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值