Python利用tkinter库制作简单的收银员App

下面我们分步实现这个APP

1.创建py文件

# 导入模块
import tkinter as tk
# 创建窗口
win = tk.Tk()
# 设置标题
win.title("收银员1.1")
# 设置窗口大小
win.geometry("400x400")
win.mainloop()

运行截图:会出现一个窗口

2. 创建Label标签定义标题

# 定义标签名
stort = tk.Label(win,text="STEGO STORE APPS\n------------------------------------------------------",font=('Arial', 12))
stort.grid(row=0,column=1)
win.mainloop()

 运行截图:

 3.创建6个标签分别为item, UnitPrice, Quantity, Discount, textTotalDiscount, textTotalPaid

 

# 项目名称
t1 = tk.Label(win,text="item")
# 定义网格,row为行,column为列,设置显示位置为第一行
t1.grid(row=1)
# 价格
t2 = tk.Label(win,text="Unit Price")
t2.grid(row=2)
# 数量
t3 = tk.Label(win,text="Quantity")
t3.grid(row=3)
# 折扣
t4 = tk.Label(win,text="Discount")
t4.grid(row=4)
# 总折扣价
t5 = tk.Label(win,text="txtTotalDiscount")
t5.grid(row=6)
# 总付款
t6 = tk.Label(win,text="txtTotaIPaid")
t6.grid(row=7)

 运行截图:

4. 创建前4个输入框

# 项目输入框
itemE = tk.Entry(win,bd =5)
# 定义网格,row为行,column为列,设置显示位置为第一行,第一列,显示在项目标签后
# padx:设置控件周围水平方向空白区域保留大小; pady:设置控件周围垂直方向空白区域保留大小;
itemE.grid(row=1, column=1, padx=10, pady=5)
# 价格输入框
Price = tk.Entry(win,bd =5)
Price.grid(row=2, column=1, padx=10, pady=5)
# 数量输入框
Quantity = tk.Entry(win,bd=5)
Quantity.grid(row=3,column=1,padx=10,pady=5)
# 折扣输入框
Discount = tk.Entry(win,bd=5,width=5)
Discount.grid(row=4,column=1,padx=10,pady=5)

 运行截图

 5.添加点击事件和总折扣标签,总付款标签

# 总折扣价
txtTotalDiscount = tk.Label(win,text="")
txtTotalDiscount.grid(row=6,column=1,padx=10,pady=5)
# 总付款
txtTotaIPaid = tk.Label(win,text="")
txtTotaIPaid.grid(row=7,column=1,padx=10,pady=5)

def ClickMe():
"""点击按钮计算总折扣价和总付款"""
price = int(Price.get()) # 获取价格输入框中的数据,需要计算,转为Int类型
quantity = int(Quantity.get()) # 获取数量输入框中的数据
discount = int(Discount.get())*0.1 # 获取折扣数据,乘以0.1进行折扣计算,输入数值为1~10
TotalDiscount = (price - price * discount) * quantity # 计算总折扣价
TotalPaid = price * quantity - TotalDiscount # 计算总付款价
txtTotalDiscount.configure(text=str(TotalDiscount))
txtTotaIPaid.configure(text=str(TotalPaid))
# 定义按钮
butt = tk.Button(win,text="Process",command=ClickMe)
butt.grid(row=5,column=1)
win.mainloop()

运行截图:

 运行截图

 6.输入数字,并运行

 

7.win.mainloop()   为窗口末端,应该放在代码最后

mainloop就进入到事件(消息)循环

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
python开发的真实星空显示软件 含真实恒星位置数据3144颗 代码讲解见: https://blog.csdn.net/xiaorang/article/details/106598307 数据格式例: {'long': 0.023278328898474372, 'lat': -0.09961466705757636, 'light': 46, 'const': 66}, {'long': 0.024870941840919196, 'lat': 0.2338062439126301, 'light': 55, 'const': 62}, {'long': 0.028107061526797, 'lat': 1.1204335039257496, 'light': 56, 'const': 18}, {'long': 0.03660100303760025, 'lat': 0.5077259659824991, 'light': 21, 'const': 1}, {'long': 0.04004802831028905, 'lat': 1.0323574005393255, 'light': 23, 'const': 18}, {'long': 0.03944444109507185, 'lat': 0.3178583859888262, 'light': 55, 'const': 62}, {'long': 0.040797071265367454, 'lat': -0.488478858963941, 'light': 54, 'const': 74}, {'long': 0.0410661312228549, 'lat': -0.798444499556106, 'light': 39, 'const': 64}, {'long': 0.043800486202076855, 'lat': 0.1945266317121166, 'light': 55, 'const': 66}, {'long': 0.045036755271142, 'lat': 0.804111967609767, 'light': 50, 'const': 1}, {'long': 0.043785947609407745, 'lat': -1.4350775693910554, 'light': 53, 'const': 58}, {'long': 0.04915283505929031, 'lat': -0.2699684886295715, 'light': 49, 'const': 21}, {'long': 0.050498187206605094, 'lat': -0.4851966800391031, 'light': 54, 'const': 74}, {'long': 0.05119631890740283, 'lat': -0.6131874860342564, 'light': 52, 'const': 74}, {'long': 0.05775584219505068, 'lat': 0.26500400429202875, 'light': 28, 'const': 62}, {'long': 0.05896303407877759, 'lat': 0.7162006931179011, 'light': 57, 'const': 1}, {'long': 0.06371905629046214, 'lat': 0.3526728525507925, 'light': 48, 'const': 62}, {'long': 0.06387905062299246, 'lat': -0.33043929519585447, 'light': 44, 'const': 21}, 代码解说详细的教程见: https://blog.csdn.net/xiaorang/article/details/106598307

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值