python+pyqt5实现KFC点餐收银系统

时间:2022-12-12 14:11:47

本文实例为大家分享了python实现kfc点餐收银系统的具体代码,供大家参考,具体内容如下

这个kfc收银系统我实现了的以下功能:

1.正常餐品结算和找零。
2.基本套餐结算和找零。
3.使用优惠劵购买餐品结算和找零。
4.可在一定时间段参与店内活动
5.模拟打印小票的功能(写到文件中)。

工程文件:

python+pyqt5实现KFC点餐收银系统

肯德基.py文件实现各功能、kfctip.txt文件用于打印小票、picture文件里存放界面所需的图片、其他四个文件为各界面布局。

主界面:

python+pyqt5实现KFC点餐收银系统

正常餐品点餐界面:

python+pyqt5实现KFC点餐收银系统

套餐点餐界面:

python+pyqt5实现KFC点餐收银系统

活动套餐点餐界面:

python+pyqt5实现KFC点餐收银系统

当点击第二个活动套餐时:

python+pyqt5实现KFC点餐收银系统

加入订单点击返回后主界面会生成订单信息:

python+pyqt5实现KFC点餐收银系统

点击结算:

python+pyqt5实现KFC点餐收银系统
python+pyqt5实现KFC点餐收银系统
python+pyqt5实现KFC点餐收银系统

打印小票到文件:

python+pyqt5实现KFC点餐收银系统

以下是代码实现:

界面布局均使用pyqt5

主界面布局:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from pyqt5 import qtcore, qtwidgets
 
class ui_mainwindow(object):
 def setupui(self, mainwindow):
 mainwindow.setobjectname("mainwindow")
 mainwindow.resize(893, 489)
 self.centralwidget = qtwidgets.qwidget(mainwindow)
 self.centralwidget.setobjectname("centralwidget")
 self.pushbutton_2 = qtwidgets.qpushbutton(self.centralwidget)
 self.pushbutton_2.setgeometry(qtcore.qrect(510, 20, 101, 41))
 self.pushbutton_2.setobjectname("pushbutton_2")
 self.pushbutton_3 = qtwidgets.qpushbutton(self.centralwidget)
 self.pushbutton_3.setgeometry(qtcore.qrect(510, 80, 101, 41))
 self.pushbutton_3.setobjectname("pushbutton_3")
 self.pushbutton_4 = qtwidgets.qpushbutton(self.centralwidget)
 self.pushbutton_4.setgeometry(qtcore.qrect(510, 140, 101, 41))
 self.pushbutton_4.setobjectname("pushbutton_4")
 self.label = qtwidgets.qlabel(self.centralwidget)
 self.label.setgeometry(qtcore.qrect(510, 200, 111, 21))
 self.label.setobjectname("label")
 self.label_2 = qtwidgets.qlabel(self.centralwidget)
 self.label_2.setgeometry(qtcore.qrect(510, 230, 72, 15))
 self.label_2.setobjectname("label_2")
 self.label_3 = qtwidgets.qlabel(self.centralwidget)
 self.label_3.setgeometry(qtcore.qrect(590, 230, 21, 16))
 self.label_3.setobjectname("label_3")
 self.label_4 = qtwidgets.qlabel(self.centralwidget)
 self.label_4.setgeometry(qtcore.qrect(510, 260, 81, 21))
 self.label_4.setobjectname("label_4")
 self.label_5 = qtwidgets.qlabel(self.centralwidget)
 self.label_5.setgeometry(qtcore.qrect(510, 290, 72, 15))
 self.label_5.setobjectname("label_5")
 self.label_6 = qtwidgets.qlabel(self.centralwidget)
 self.label_6.setgeometry(qtcore.qrect(590, 290, 21, 16))
 self.label_6.setobjectname("label_6")
 self.label_7 = qtwidgets.qlabel(self.centralwidget)
 self.label_7.setgeometry(qtcore.qrect(640, 20, 61, 21))
 self.label_7.setobjectname("label_7")
 self.tablewidget = qtwidgets.qtablewidget(self.centralwidget)
 self.tablewidget.setgeometry(qtcore.qrect(640, 40, 241, 231))
 self.tablewidget.setobjectname("tablewidget")
 self.tablewidget.setcolumncount(3)
 self.tablewidget.setrowcount(0)
 item = qtwidgets.qtablewidgetitem()
 self.tablewidget.sethorizontalheaderitem(0, item)
 item = qtwidgets.qtablewidgetitem()
 self.tablewidget.sethorizontalheaderitem(1, item)
 item = qtwidgets.qtablewidgetitem()
 self.tablewidget.sethorizontalheaderitem(2, item)
 self.tablewidget.horizontalheader().setdefaultsectionsize(70)
 self.pushbutton_5 = qtwidgets.qpushbutton(self.centralwidget)
 self.pushbutton_5.setgeometry(qtcore.qrect(640, 290, 71, 31))
 self.pushbutton_5.setobjectname("pushbutton_5")
 self.pushbutton_6 = qtwidgets.qpushbutton(self.centralwidget)
 self.pushbutton_6.setgeometry(qtcore.qrect(640, 350, 91, 31))
 self.pushbutton_6.setobjectname("pushbutton_6")
 self.pushbutton_7 = qtwidgets.qpushbutton(self.centralwidget)
 self.pushbutton_7.setgeometry(qtcore.qrect(750, 350, 91, 31))
 self.pushbutton_7.setobjectname("pushbutton_7")
 self.label_8 = qtwidgets.qlabel(self.centralwidget)
 self.label_8.setgeometry(qtcore.qrect(10, 10, 481, 431))
 self.label_8.setobjectname("label_8")
 mainwindow.setcentralwidget(self.centralwidget)
 self.menubar = qtwidgets.qmenubar(mainwindow)
 self.menubar.setgeometry(qtcore.qrect(0, 0, 893, 26))
 self.menubar.setobjectname("menubar")
 mainwindow.setmenubar(self.menubar)
 self.statusbar = qtwidgets.qstatusbar(mainwindow)
 self.statusbar.setobjectname("statusbar")
 mainwindow.setstatusbar(self.statusbar)
 
 self.retranslateui(mainwindow)
 qtcore.qmetaobject.connectslotsbyname(mainwindow)
 
 def retranslateui(self, mainwindow):
 _translate = qtcore.qcoreapplication.translate
 mainwindow.setwindowtitle(_translate("mainwindow", "肯德基"))
 self.pushbutton_2.settext(_translate("mainwindow", "基本餐"))
 self.pushbutton_3.settext(_translate("mainwindow", "套餐"))
 self.pushbutton_4.settext(_translate("mainwindow", "活动"))
 self.label.settext(_translate("mainwindow", "会员储值卡余额"))
 self.label_2.settext(_translate("mainwindow", "钱"))
 self.label_3.settext(_translate("mainwindow", "元"))
 self.label_4.settext(_translate("mainwindow", "您的优惠券"))
 self.label_5.settext(_translate("mainwindow", "券"))
 self.label_6.settext(_translate("mainwindow", "张"))
 self.label_7.settext(_translate("mainwindow", "您的订单"))
 item = self.tablewidget.horizontalheaderitem(0)
 item.settext(_translate("mainwindow", "名称"))
 item = self.tablewidget.horizontalheaderitem(1)
 item.settext(_translate("mainwindow", "数量"))
 item = self.tablewidget.horizontalheaderitem(2)
 item.settext(_translate("mainwindow", "价格/元"))
 self.pushbutton_5.settext(_translate("mainwindow", "删除"))
 self.pushbutton_6.settext(_translate("mainwindow", "结算"))
 self.pushbutton_7.settext(_translate("mainwindow", "打印小票"))
 self.label_8.settext(_translate("mainwindow", "图"))

正常套餐界面:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from pyqt5 import qtcore, qtwidgets
 
class ui_normal(object):
 def setupui(self, form):
 form.setobjectname("form")
 form.resize(728, 459)
 self.pushbutton = qtwidgets.qpushbutton(form)
 self.pushbutton.setgeometry(qtcore.qrect(40, 190, 93, 41))
 self.pushbutton.setobjectname("pushbutton")
 self.pushbutton_2 = qtwidgets.qpushbutton(form)
 self.pushbutton_2.setgeometry(qtcore.qrect(260, 190, 93, 41))
 self.pushbutton_2.setobjectname("pushbutton_2")
 self.pushbutton_3 = qtwidgets.qpushbutton(form)
 self.pushbutton_3.setgeometry(qtcore.qrect(480, 190, 93, 41))
 self.pushbutton_3.setobjectname("pushbutton_3")
 self.pushbutton_4 = qtwidgets.qpushbutton(form)
 self.pushbutton_4.setgeometry(qtcore.qrect(40, 400, 93, 41))
 self.pushbutton_4.setobjectname("pushbutton_4")
 self.pushbutton_5 = qtwidgets.qpushbutton(form)
 self.pushbutton_5.setgeometry(qtcore.qrect(620, 400, 93, 41))
 self.pushbutton_5.setobjectname("pushbutton_5")
 self.pushbutton_6 = qtwidgets.qpushbutton(form)
 self.pushbutton_6.setgeometry(qtcore.qrect(260, 400, 93, 41))
 self.pushbutton_6.setobjectname("pushbutton_6")
 self.label = qtwidgets.qlabel(form)
 self.label.setgeometry(qtcore.qrect(50, 170, 72, 15))
 self.label.setobjectname("label")
 self.label_2 = qtwidgets.qlabel(form)
 self.label_2.setgeometry(qtcore.qrect(30, 140, 121, 21))
 self.label_2.setobjectname("label_2")
 self.label_3 = qtwidgets.qlabel(form)
 self.label_3.setgeometry(qtcore.qrect(30, 10, 121, 111))
 self.label_3.setobjectname("label_3")
 self.label_4 = qtwidgets.qlabel(form)
 self.label_4.setgeometry(qtcore.qrect(270, 170, 72, 15))
 self.label_4.setobjectname("label_4")
 self.label_5 = qtwidgets.qlabel(form)
 self.label_5.setgeometry(qtcore.qrect(270, 140, 72, 15))
 self.label_5.setobjectname("label_5")
 self.label_6 = qtwidgets.qlabel(form)
 self.label_6.setgeometry(qtcore.qrect(240, 10, 131, 111))
 self.label_6.setobjectname("label_6")
 self.label_7 = qtwidgets.qlabel(form)
 self.label_7.setgeometry(qtcore.qrect(490, 170, 72, 15))
 self.label_7.setobjectname("label_7")
 self.label_8 = qtwidgets.qlabel(form)
 self.label_8.setgeometry(qtcore.qrect(480, 140, 91, 16))
 self.label_8.setobjectname("label_8")
 self.label_9 = qtwidgets.qlabel(form)
 self.label_9.setgeometry(qtcore.qrect(460, 10, 131, 111))
 self.label_9.setobjectname("label_9")
 self.label_10 = qtwidgets.qlabel(form)
 self.label_10.setgeometry(qtcore.qrect(50, 380, 72, 15))
 self.label_10.setobjectname("label_10")
 self.label_11 = qtwidgets.qlabel(form)
 self.label_11.setgeometry(qtcore.qrect(60, 360, 51, 16))
 self.label_11.setobjectname("label_11")
 self.label_12 = qtwidgets.qlabel(form)
 self.label_12.setgeometry(qtcore.qrect(30, 250, 121, 101))
 self.label_12.setobjectname("label_12")
 self.label_13 = qtwidgets.qlabel(form)
 self.label_13.setgeometry(qtcore.qrect(270, 380, 72, 15))
 self.label_13.setobjectname("label_13")
 self.label_14 = qtwidgets.qlabel(form)
 self.label_14.setgeometry(qtcore.qrect(250, 360, 131, 16))
 self.label_14.setobjectname("label_14")
 self.label_15 = qtwidgets.qlabel(form)
 self.label_15.setgeometry(qtcore.qrect(240, 250, 131, 101))
 self.label_15.setobjectname("label_15")
 
 self.retranslateui(form)
 qtcore.qmetaobject.connectslotsbyname(form)
 
 def retranslateui(self, form):
 _translate = qtcore.qcoreapplication.translate
 form.setwindowtitle(_translate("form", "form"))
 self.pushbutton.settext(_translate("form", "加入订单"))
 self.pushbutton_2.settext(_translate("form", "加入订单"))
 self.pushbutton_3.settext(_translate("form", "加入订单"))
 self.pushbutton_4.settext(_translate("form", "加入订单"))
 self.pushbutton_5.settext(_translate("form", "返回"))
 self.pushbutton_6.settext(_translate("form", "加入订单"))
 self.label.settext(_translate("form", "钱1"))
 self.label_2.settext(_translate("form", "新奥尔良烤鸡腿堡"))
 self.label_3.settext(_translate("form", "textlabel"))
 self.label_4.settext(_translate("form", "钱2"))
 self.label_5.settext(_translate("form", "香辣鸡翅"))
 self.label_6.settext(_translate("form", "textlabel"))
 self.label_7.settext(_translate("form", "钱3"))
 self.label_8.settext(_translate("form", "波纹霸王薯条"))
 self.label_9.settext(_translate("form", "textlabel"))
 self.label_10.settext(_translate("form", "钱4"))
 self.label_11.settext(_translate("form", "乌龙茶"))
 self.label_12.settext(_translate("form", "textlabel"))
 self.label_13.settext(_translate("form", "钱5"))
 self.label_14.settext(_translate("form", "原味圣代(草莓酱)"))
 self.label_15.settext(_translate("form", "textlabel"))

套餐界面:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from pyqt5 import qtcore, qtwidgets
 
class ui_package(object):
 def setupui(self, form):
 form.setobjectname("form")
 form.resize(728, 393)
 self.pushbutton = qtwidgets.qpushbutton(form)
 self.pushbutton.setgeometry(qtcore.qrect(90, 280, 91, 31))
 self.pushbutton.setobjectname("pushbutton")
 self.pushbutton_2 = qtwidgets.qpushbutton(form)
 self.pushbutton_2.setgeometry(qtcore.qrect(340, 280, 93, 31))
 self.pushbutton_2.setobjectname("pushbutton_2")
 self.label = qtwidgets.qlabel(form)
 self.label.setgeometry(qtcore.qrect(100, 250, 72, 15))
 self.label.setobjectname("label")
 self.label_2 = qtwidgets.qlabel(form)
 self.label_2.setgeometry(qtcore.qrect(350, 250, 72, 15))
 self.label_2.setobjectname("label_2")
 self.label_3 = qtwidgets.qlabel(form)
 self.label_3.setgeometry(qtcore.qrect(80, 220, 131, 21))
 self.label_3.setobjectname("label_3")
 self.label_4 = qtwidgets.qlabel(form)
 self.label_4.setgeometry(qtcore.qrect(330, 220, 111, 21))
 self.label_4.setobjectname("label_4")
 self.label_5 = qtwidgets.qlabel(form)
 self.label_5.setgeometry(qtcore.qrect(60, 20, 161, 171))
 self.label_5.setobjectname("label_5")
 self.label_6 = qtwidgets.qlabel(form)
 self.label_6.setgeometry(qtcore.qrect(300, 20, 171, 171))
 self.label_6.setobjectname("label_6")
 self.pushbutton_3 = qtwidgets.qpushbutton(form)
 self.pushbutton_3.setgeometry(qtcore.qrect(560, 280, 101, 41))
 self.pushbutton_3.setobjectname("pushbutton_3")
 
 self.retranslateui(form)
 qtcore.qmetaobject.connectslotsbyname(form)
 
 def retranslateui(self, form):
 _translate = qtcore.qcoreapplication.translate
 form.setwindowtitle(_translate("form", "form"))
 self.pushbutton.settext(_translate("form", "加入订单"))
 self.pushbutton_2.settext(_translate("form", "加入订单"))
 self.label.settext(_translate("form", "钱1"))
 self.label_2.settext(_translate("form", "钱2"))
 self.label_3.settext(_translate("form", "翅桶辣堡奥堡套餐"))
 self.label_4.settext(_translate("form", "万圣节日劲堡桶"))
 self.label_5.settext(_translate("form", "textlabel"))
 self.label_6.settext(_translate("form", "textlabel"))
 self.pushbutton_3.settext(_translate("form", "返回"))

活动界面:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from pyqt5 import qtcore, qtwidgets
 
class ui_activity(object):
 def setupui(self, form):
 form.setobjectname("form")
 form.resize(639, 335)
 self.pushbutton = qtwidgets.qpushbutton(form)
 self.pushbutton.setgeometry(qtcore.qrect(50, 240, 93, 31))
 self.pushbutton.setobjectname("pushbutton")
 self.pushbutton_2 = qtwidgets.qpushbutton(form)
 self.pushbutton_2.setgeometry(qtcore.qrect(300, 240, 93, 31))
 self.pushbutton_2.setobjectname("pushbutton_2")
 self.label = qtwidgets.qlabel(form)
 self.label.setgeometry(qtcore.qrect(11, 220, 201, 20))
 self.label.setobjectname("label")
 self.label_2 = qtwidgets.qlabel(form)
 self.label_2.setgeometry(qtcore.qrect(20, 200, 161, 16))
 self.label_2.setobjectname("label_2")
 self.label_3 = qtwidgets.qlabel(form)
 self.label_3.setgeometry(qtcore.qrect(50, 180, 91, 16))
 self.label_3.setobjectname("label_3")
 self.label_4 = qtwidgets.qlabel(form)
 self.label_4.setgeometry(qtcore.qrect(30, 30, 141, 141))
 self.label_4.setobjectname("label_4")
 self.label_5 = qtwidgets.qlabel(form)
 self.label_5.setgeometry(qtcore.qrect(261, 220, 201, 20))
 self.label_5.setobjectname("label_5")
 self.label_6 = qtwidgets.qlabel(form)
 self.label_6.setgeometry(qtcore.qrect(270, 200, 161, 16))
 self.label_6.setobjectname("label_6")
 self.label_7 = qtwidgets.qlabel(form)
 self.label_7.setgeometry(qtcore.qrect(310, 180, 61, 16))
 self.label_7.setobjectname("label_7")
 self.label_8 = qtwidgets.qlabel(form)
 self.label_8.setgeometry(qtcore.qrect(280, 30, 151, 141))
 self.label_8.setobjectname("label_8")
 self.pushbutton_3 = qtwidgets.qpushbutton(form)
 self.pushbutton_3.setgeometry(qtcore.qrect(490, 250, 101, 31))
 self.pushbutton_3.setobjectname("pushbutton_3")
 
 self.retranslateui(form)
 qtcore.qmetaobject.connectslotsbyname(form)
 
 def retranslateui(self, form):
 _translate = qtcore.qcoreapplication.translate
 form.setwindowtitle(_translate("form", "form"))
 self.pushbutton.settext(_translate("form", "加入订单"))
 self.pushbutton_2.settext(_translate("form", "加入订单"))
 self.label.settext(_translate("form", "钱1"))
 self.label_2.settext(_translate("form", "2018.10.1-2018.10.31"))
 self.label_3.settext(_translate("form", "葡式蛋挞5只"))
 self.label_4.settext(_translate("form", "textlabel"))
 self.label_5.settext(_translate("form", "钱2"))
 self.label_6.settext(_translate("form", "2018.11.1-2018.11.11"))
 self.label_7.settext(_translate("form", "超级翅桶"))
 self.label_8.settext(_translate("form", "textlabel"))
 self.pushbutton_3.settext(_translate("form", "返回"))

以下为实现各界面互联和各功能的实现(注释比较详细这里就不多说了):

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
# -*- coding: utf-8 -*-
# 作者:dcjmessi
# 日期:2018/10/19
 
 
from kfcmain import *
from normal import *
from package import *
from activity import *
import sys
from pyqt5.qtwidgets import *
from pyqt5.qtgui import qpixmap
 
class kfc_main(qmainwindow):
 def __init__(self):
 qmainwindow.__init__(self)
 self.main_ui = ui_mainwindow()
 self.main_ui.setupui(self)
 
 # 给按钮绑定方法
 btn_del = self.main_ui.pushbutton_5
 btn_del.clicked.connect(self.order_del)
 btn_num = self.main_ui.pushbutton_6
 btn_num.clicked.connect(self.order_num)
 self.btn_tip = self.main_ui.pushbutton_7
 self.btn_tip.clicked.connect(self.order_tip)
 # 设置按钮为当前不可用
 self.btn_tip.setenabled(false)
 # 定义列表
 self.num = []
 self.new_num = []
 
 # 主界面显示
 def person(self):
 # 主界面贴图
 self.main_ui.label_8.setpixmap(qpixmap('./picture/主界图.png'))
 # 将图片完全填充
 self.main_ui.label_8.setscaledcontents(true)
 # 初始化会员储值余额
 self.balance = 200
 # 初始化优惠券数量
 self.coupons = 1
 # 显示余额和券数量
 self.main_ui.label_2.settext(str(self.balance))
 self.main_ui.label_5.settext(str(self.coupons))
 # 显示主界面
 kfcmain.show()
 
 # 删除tablewidget所选行
 def order_del(self):
 # 获取所选行索引
 row_index = kfcmain.main_ui.tablewidget.currentrow()
 if row_index != -1:
  # 删除
  kfcmain.main_ui.tablewidget.removerow(row_index)
 
 # 结算
 def order_num(self):
 # 设置按钮为可用
 self.btn_tip.setenabled(true)
 # 遍历所有行
 for row_index in range(kfcmain.main_ui.tablewidget.rowcount()):
  # 将每一行的第三项值添加到num列表里
  self.num.append(kfcmain.main_ui.tablewidget.item(row_index, 2).text())
 
 # 将num中的字符转换成int型
 self.new_num = eval('[' + (','.join(self.num)) + ']')
 # 将new_num列表值求和
 self.money = sum(self.new_num)
 
 # 有优惠券时
 if self.coupons >= 1:
  # 消息提示框
  button = qmessagebox.information(self, "温馨提示", "是否使用优惠券", qmessagebox.yes | qmessagebox.no)
  # 使用优惠券
  if button == qmessagebox.yes:
  # 当前优惠券数量减一
  self.coupons = self.coupons -1
  self.main_ui.label_5.settext(str(self.coupons))
 
  # 余额足够
  if self.balance >= (self.money - self.coupons * 20):
   qmessagebox.information(self, "恭喜您", "付款成功!", qmessagebox.yes)
   self.balance = self.balance - self.money - self.coupons * 20
   self.main_ui.label_2.settext(str(self.balance))
  else:
   qmessagebox.information(self, "对不起", "您的会员储值卡余额不足!", qmessagebox.yes)
  # 不使用优惠券
  else:
  if self.balance >= self.money:
   qmessagebox.information(self, "恭喜您", "付款成功!", qmessagebox.yes)
   self.balance = self.balance - self.money
   self.main_ui.label_2.settext(str(self.balance))
  else:
   qmessagebox.information(self, "对不起", "您的会员储值卡余额不足!", qmessagebox.yes)
 # 没有优惠券时
 else:
  if self.balance >= self.money:
  qmessagebox.information(self, "恭喜您", "付款成功!", qmessagebox.yes)
  self.balance = self.balance - self.money
  self.main_ui.label_2.settext(str(self.balance))
  else:
  qmessagebox.information(self, "对不起", "您的会员储值卡余额不足!", qmessagebox.yes)
 
 # 打印小票
 def order_tip(self):
 # 打开本地txt文件
 with open("kfctip.txt", "w") as f:
  # 遍历行
  for row_index in range(kfcmain.main_ui.tablewidget.rowcount()):
  # 遍历列
  for column_index in range(kfcmain.main_ui.tablewidget.columncount()):
   # 将tablewidget数据写入文件
   f.write(kfcmain.main_ui.tablewidget.item(row_index, column_index).text() + "\n")
  f.write("合计:" + str(self.money) + "元")
 f.close()
 
class normal(qwidget):
 def __init__(self):
 qwidget.__init__(self)
 self.normal_ui = ui_normal()
 self.normal_ui.setupui(self)
 
 # 初始化各基本餐加入订单按钮点击次数
 self.bt1 = 0
 self.bt2 = 0
 self.bt3 = 0
 self.bt4 = 0
 self.bt6 = 0
 # 初始化返回按钮点击次数
 self.bt5 = 0
 # 按钮绑定方法
 btn_hamburg = self.normal_ui.pushbutton
 btn_hamburg.clicked.connect(self.order_hamburg)
 btn_chicken = self.normal_ui.pushbutton_2
 btn_chicken.clicked.connect(self.order_chicken)
 btn_fries = self.normal_ui.pushbutton_3
 btn_fries.clicked.connect(self.order_fries)
 btn_tea = self.normal_ui.pushbutton_4
 btn_tea.clicked.connect(self.order_tea)
 btn_ice = self.normal_ui.pushbutton_6
 btn_ice.clicked.connect(self.order_ice)
 btn_return = self.normal_ui.pushbutton_5
 btn_return.clicked.connect(self.nor_show)
 
 # 显示基本餐界面
 def nor_order(self):
 self.normal_ui.label_3.setpixmap(qpixmap('./picture/新奥尔良.png'))
 self.normal_ui.label_3.setscaledcontents(true)
 self.normal_ui.label_6.setpixmap(qpixmap('./picture/鸡翅.png'))
 self.normal_ui.label_6.setscaledcontents(true)
 self.normal_ui.label_9.setpixmap(qpixmap('./picture/薯条.png'))
 self.normal_ui.label_9.setscaledcontents(true)
 self.normal_ui.label_12.setpixmap(qpixmap('./picture/乌龙茶.png'))
 self.normal_ui.label_12.setscaledcontents(true)
 self.normal_ui.label_15.setpixmap(qpixmap('./picture/冰淇淋.png'))
 self.normal_ui.label_15.setscaledcontents(true)
 # 基本餐价格
 self.price_hamburg = 18.5
 self.price_chicken = 11.0
 self.price_fries = 13.0
 self.price_tea = 13.5
 self.price_ice = 10.0
 # 显示价格
 self.normal_ui.label.settext(str(self.price_hamburg)+"元/份")
 self.normal_ui.label_4.settext(str(self.price_chicken)+"元/份")
 self.normal_ui.label_7.settext(str(self.price_fries)+"元/份")
 self.normal_ui.label_10.settext(str(self.price_tea)+"元/份")
 self.normal_ui.label_13.settext(str(self.price_ice)+"元/份")
 normal.show()
 
 # 计算点击次数
 def order_hamburg(self):
 self.bt1 += 1
 
 def order_chicken(self):
 self.bt2 += 1
 
 def order_fries(self):
 self.bt3 += 1
 
 def order_tea(self):
 self.bt4 += 1
 
 def order_ice(self):
 self.bt6 += 1
 
 def nor_show(self):
 self.bt5 += 1
 
 # 隐藏界面
 normal.hide()
 
 # 获取所选各基本餐的数量对应的价格
 self.num_hamburg = self.price_hamburg * self.bt1
 self.num_chicken = self.price_chicken * self.bt2
 self.num_fries = self.price_fries * self.bt3
 self.num_tea = self.price_tea * self.bt4
 self.num_ice = self.price_ice * self.bt6
 
 # 不是第一次进入该界面
 if self.bt5 > 1:
  for row_index in range(kfcmain.main_ui.tablewidget.rowcount()):
  # 获取tablewidget的所有名称,并放入name列表
  name.append(kfcmain.main_ui.tablewidget.item(row_index, 0).text())
  if '新奥尔良烤鸡腿堡' in name:
  # 重新设置该行的数量和价格
  kfcmain.main_ui.tablewidget.setitem(name.index('新奥尔良烤鸡腿堡'), 1, qtablewidgetitem("×" + str(self.bt1)))
  kfcmain.main_ui.tablewidget.setitem(name.index('新奥尔良烤鸡腿堡'), 2, qtablewidgetitem(str(self.num_hamburg)))
  if '新奥尔良烤鸡腿堡' not in name:
  # 已选择
  if self.bt1 != 0:
   # 添加一行数据
   row_count = kfcmain.main_ui.tablewidget.rowcount()
   kfcmain.main_ui.tablewidget.insertrow(row_count)
   kfcmain.main_ui.tablewidget.setitem(row_count, 0, qtablewidgetitem(normal.normal_ui.label_2.text()))
   kfcmain.main_ui.tablewidget.setitem(row_count, 1, qtablewidgetitem("×" + str(self.bt1)))
   kfcmain.main_ui.tablewidget.setitem(row_count, 2, qtablewidgetitem(str(self.num_hamburg)))
  if '香辣鸡翅' in name:
  kfcmain.main_ui.tablewidget.setitem(name.index('香辣鸡翅'), 1, qtablewidgetitem("×" + str(self.bt2)))
  kfcmain.main_ui.tablewidget.setitem(name.index('香辣鸡翅'), 2, qtablewidgetitem(str(self.num_chicken)))
  if '香辣鸡翅' not in name:
  if self.bt2 != 0:
   row_count = kfcmain.main_ui.tablewidget.rowcount()
   kfcmain.main_ui.tablewidget.insertrow(row_count)
   kfcmain.main_ui.tablewidget.setitem(row_count, 0, qtablewidgetitem(normal.normal_ui.label_5.text()))
   kfcmain.main_ui.tablewidget.setitem(row_count, 1, qtablewidgetitem("×" + str(self.bt2)))
   kfcmain.main_ui.tablewidget.setitem(row_count, 2, qtablewidgetitem(str(self.num_chicken)))
  if '波纹霸王薯条' in name:
  kfcmain.main_ui.tablewidget.setitem(name.index('波纹霸王薯条'), 1, qtablewidgetitem("×" + str(self.bt3)))
  kfcmain.main_ui.tablewidget.setitem(name.index('波纹霸王薯条'), 2, qtablewidgetitem(str(self.num_fries)))
  if '波纹霸王薯条' not in name:
  if self.bt3 != 0:
   row_count = kfcmain.main_ui.tablewidget.rowcount()
   kfcmain.main_ui.tablewidget.insertrow(row_count)
   kfcmain.main_ui.tablewidget.setitem(row_count, 0, qtablewidgetitem(normal.normal_ui.label_8.text()))
   kfcmain.main_ui.tablewidget.setitem(row_count, 1, qtablewidgetitem("×" + str(self.bt3)))
   kfcmain.main_ui.tablewidget.setitem(row_count, 2, qtablewidgetitem(str(self.num_fries)))
  if '乌龙茶'in name:
  kfcmain.main_ui.tablewidget.setitem(name.index('乌龙茶'), 1, qtablewidgetitem("×" + str(self.bt4)))
  kfcmain.main_ui.tablewidget.setitem(name.index('乌龙茶'), 2, qtablewidgetitem(str(self.num_tea)))
  if '乌龙茶' not in name:
  if self.bt4 != 0:
   row_count = kfcmain.main_ui.tablewidget.rowcount()
   kfcmain.main_ui.tablewidget.insertrow(row_count)
   kfcmain.main_ui.tablewidget.setitem(row_count, 0, qtablewidgetitem(normal.normal_ui.label_11.text()))
   kfcmain.main_ui.tablewidget.setitem(row_count, 1, qtablewidgetitem("×" + str(self.bt4)))
   kfcmain.main_ui.tablewidget.setitem(row_count, 2, qtablewidgetitem(str(self.num_tea)))
  if '原味圣代(草莓酱)' in name:
  kfcmain.main_ui.tablewidget.setitem(name.index('原味圣代(草莓酱)'), 1, qtablewidgetitem("×" + str(self.bt6)))
  kfcmain.main_ui.tablewidget.setitem(name.index('原味圣代(草莓酱)'), 2, qtablewidgetitem(str(self.num_ice)))
  if '原味圣代(草莓酱)' not in name:
  if self.bt6 != 0:
   row_count = kfcmain.main_ui.tablewidget.rowcount()
   kfcmain.main_ui.tablewidget.insertrow(row_count)
   kfcmain.main_ui.tablewidget.setitem(row_count, 0, qtablewidgetitem(normal.normal_ui.label_14.text()))
   kfcmain.main_ui.tablewidget.setitem(row_count, 1, qtablewidgetitem("×" + str(self.bt6)))
   kfcmain.main_ui.tablewidget.setitem(row_count, 2, qtablewidgetitem(str(self.num_ice)))
 # 第一次进入该界面
 else:
  if self.bt1 != 0:
  row_count = kfcmain.main_ui.tablewidget.rowcount()
  kfcmain.main_ui.tablewidget.insertrow(row_count)
  kfcmain.main_ui.tablewidget.setitem(row_count, 0, qtablewidgetitem(normal.normal_ui.label_2.text()))
  kfcmain.main_ui.tablewidget.setitem(row_count, 1, qtablewidgetitem("×" + str(self.bt1)))
  kfcmain.main_ui.tablewidget.setitem(row_count, 2, qtablewidgetitem(str(self.num_hamburg)))
  if self.bt2 != 0:
  row_count = kfcmain.main_ui.tablewidget.rowcount()
  kfcmain.main_ui.tablewidget.insertrow(row_count)
  kfcmain.main_ui.tablewidget.setitem(row_count, 0, qtablewidgetitem(normal.normal_ui.label_5.text()))
  kfcmain.main_ui.tablewidget.setitem(row_count, 1, qtablewidgetitem("×" + str(self.bt2)))
  kfcmain.main_ui.tablewidget.setitem(row_count, 2, qtablewidgetitem(str(self.num_chicken)))
  if self.bt3 != 0:
  row_count = kfcmain.main_ui.tablewidget.rowcount()
  kfcmain.main_ui.tablewidget.insertrow(row_count)
  kfcmain.main_ui.tablewidget.setitem(row_count, 0, qtablewidgetitem(normal.normal_ui.label_8.text()))
  kfcmain.main_ui.tablewidget.setitem(row_count, 1, qtablewidgetitem("×" + str(self.bt3)))
  kfcmain.main_ui.tablewidget.setitem(row_count, 2, qtablewidgetitem(str(self.num_fries)))
  if self.bt4 != 0:
  row_count = kfcmain.main_ui.tablewidget.rowcount()
  kfcmain.main_ui.tablewidget.insertrow(row_count)
  kfcmain.main_ui.tablewidget.setitem(row_count, 0, qtablewidgetitem(normal.normal_ui.label_11.text()))
  kfcmain.main_ui.tablewidget.setitem(row_count, 1, qtablewidgetitem("×" + str(self.bt4)))
  kfcmain.main_ui.tablewidget.setitem(row_count, 2, qtablewidgetitem(str(self.num_tea)))
  if self.bt6 != 0:
  row_count = kfcmain.main_ui.tablewidget.rowcount()
  kfcmain.main_ui.tablewidget.insertrow(row_count)
  kfcmain.main_ui.tablewidget.setitem(row_count, 0, qtablewidgetitem(normal.normal_ui.label_14.text()))
  kfcmain.main_ui.tablewidget.setitem(row_count, 1, qtablewidgetitem("×" + str(self.bt6)))
  kfcmain.main_ui.tablewidget.setitem(row_count, 2, qtablewidgetitem(str(self.num_ice)))
 
class package(qwidget):
 def __init__(self):
 qwidget.__init__(self)
 self.package_ui = ui_package()
 self.package_ui.setupui(self)
 
 # 初始化各套餐加入订单按钮点击次数
 self.bt1 = 0
 self.bt2 = 0
 # 初始化返回按钮点击次数
 self.bt3 = 0
 # 按钮绑定方法
 btn_pack1 = self.package_ui.pushbutton
 btn_pack1.clicked.connect(self.order_pack1)
 btn_pack2 = self.package_ui.pushbutton_2
 btn_pack2.clicked.connect(self.order_pack2)
 btn_return = self.package_ui.pushbutton_3
 btn_return.clicked.connect(self.pac_show)
 
 # 显示套餐界面
 def pac_order(self):
 self.package_ui.label_5.setpixmap(qpixmap('./picture/套餐2.png'))
 self.package_ui.label_5.setscaledcontents(true)
 self.package_ui.label_6.setpixmap(qpixmap('./picture/套餐1.png'))
 self.package_ui.label_6.setscaledcontents(true)
 # 套餐价格
 self.price_pack1 = 89.0
 self.price_pack2 = 67.0
 self.package_ui.label.settext(str(self.price_pack1)+"元/份")
 self.package_ui.label_2.settext(str(self.price_pack2)+"元/份")
 package.show()
 
 def order_pack1(self):
 self.bt1 += 1
 
 def order_pack2(self):
 self.bt2 += 1
 
 def pac_show(self):
 self.bt3 += 1
 
 package.hide()
 
 self.num_pack1 = self.price_pack1 * self.bt1
 self.num_pack2 = self.price_pack2 * self.bt2
 
 if self.bt3 > 1:
  for row_index in range(kfcmain.main_ui.tablewidget.rowcount()):
  name.append(kfcmain.main_ui.tablewidget.item(row_index, 0).text())
  if '翅桶辣堡奥堡套餐' in name:
  kfcmain.main_ui.tablewidget.setitem(name.index('翅桶辣堡奥堡套餐'), 1, qtablewidgetitem("×" + str(self.bt1)))
  kfcmain.main_ui.tablewidget.setitem(name.index('翅桶辣堡奥堡套餐'), 2, qtablewidgetitem(str(self.num_pack1)))
  if '翅桶辣堡奥堡套餐' not in name:
  if self.bt1 != 0:
   row_count = kfcmain.main_ui.tablewidget.rowcount()
   kfcmain.main_ui.tablewidget.insertrow(row_count)
   kfcmain.main_ui.tablewidget.setitem(row_count, 0, qtablewidgetitem(package.package_ui.label_3.text()))
   kfcmain.main_ui.tablewidget.setitem(row_count, 1, qtablewidgetitem("×" + str(self.bt1)))
   kfcmain.main_ui.tablewidget.setitem(row_count, 2, qtablewidgetitem(str(self.num_pack1)))
  if '万圣节日劲堡桶' in name:
  kfcmain.main_ui.tablewidget.setitem(name.index('万圣节日劲堡桶'), 1, qtablewidgetitem("×" + str(self.bt2)))
  kfcmain.main_ui.tablewidget.setitem(name.index('万圣节日劲堡桶'), 2, qtablewidgetitem(str(self.num_pack2)))
  if '万圣节日劲堡桶' not in name:
  if self.bt2 != 0:
   row_count = kfcmain.main_ui.tablewidget.rowcount()
   kfcmain.main_ui.tablewidget.insertrow(row_count)
   kfcmain.main_ui.tablewidget.setitem(row_count, 0, qtablewidgetitem(package.package_ui.label_4.text()))
   kfcmain.main_ui.tablewidget.setitem(row_count, 1, qtablewidgetitem("×" + str(self.bt2)))
   kfcmain.main_ui.tablewidget.setitem(row_count, 2, qtablewidgetitem(str(self.num_pack2)))
 else:
  if self.bt1 != 0:
  row_count = kfcmain.main_ui.tablewidget.rowcount()
  kfcmain.main_ui.tablewidget.insertrow(row_count)
  kfcmain.main_ui.tablewidget.setitem(row_count, 0, qtablewidgetitem(package.package_ui.label_3.text()))
  kfcmain.main_ui.tablewidget.setitem(row_count, 1, qtablewidgetitem("×" + str(self.bt1)))
  kfcmain.main_ui.tablewidget.setitem(row_count, 2, qtablewidgetitem(str(self.num_pack1)))
  if self.bt2 != 0:
  row_count = kfcmain.main_ui.tablewidget.rowcount()
  kfcmain.main_ui.tablewidget.insertrow(row_count)
  kfcmain.main_ui.tablewidget.setitem(row_count, 0, qtablewidgetitem(package.package_ui.label_4.text()))
  kfcmain.main_ui.tablewidget.setitem(row_count, 1, qtablewidgetitem("×" + str(self.bt2)))
  kfcmain.main_ui.tablewidget.setitem(row_count, 2, qtablewidgetitem(str(self.num_pack2)))
 
class activity(qwidget):
 def __init__(self):
 qwidget.__init__(self)
 self.activity_ui = ui_activity()
 self.activity_ui.setupui(self)
 
 # 初始化各活动加入订单按钮点击次数
 self.bt1 = 0
 # 初始化返回按钮点击次数
 self.bt3 = 0
 # 绑定方法
 btn_act1 = self.activity_ui.pushbutton
 btn_act1.clicked.connect(self.order_act1)
 btn_act2 = self.activity_ui.pushbutton_2
 btn_act2.clicked.connect(self.order_act2)
 btn_return = self.activity_ui.pushbutton_3
 btn_return.clicked.connect(self.act_show)
 
 def act_order(self):
 self.activity_ui.label_4.setpixmap(qpixmap('./picture/活动1.png'))
 self.activity_ui.label_4.setscaledcontents(true)
 self.activity_ui.label_8.setpixmap(qpixmap('./picture/活动2.png'))
 self.activity_ui.label_8.setscaledcontents(true)
 # 活动价格
 self.price_act1 = 29.0
 self.price_act2 = 69.0
 self.activity_ui.label.settext(str(self.price_act1) + "元/份 原价:"+str(self.price_act1 + 7) + "元/份")
 self.activity_ui.label_5.settext(str(self.price_act2) + "元/份 原价:"+str(self.price_act2 + 10) + "元/份")
 activity.show()
 
 def order_act1(self):
 self.bt1 += 1
 
 def order_act2(self):
 qmessagebox.information(self, "对不起", "活动还没有开始,敬请期待!", qmessagebox.yes)
 
 def act_show(self):
 self.bt3 += 1
 
 activity.hide()
 
 self.num_act1 = self.price_act1 * self.bt1
 
 if self.bt3 > 1:
  for row_index in range(kfcmain.main_ui.tablewidget.rowcount()):
  name.append(kfcmain.main_ui.tablewidget.item(row_index, 0).text())
  if '葡式蛋挞5只' in name:
  kfcmain.main_ui.tablewidget.setitem(name.index('葡式蛋挞5只'), 1, qtablewidgetitem("×" + str(self.bt1)))
  kfcmain.main_ui.tablewidget.setitem(name.index('葡式蛋挞5只'), 2, qtablewidgetitem(str(self.num_act1)))
  if '葡式蛋挞5只' not in name:
  if self.bt1 != 0:
   row_count = kfcmain.main_ui.tablewidget.rowcount()
   kfcmain.main_ui.tablewidget.insertrow(row_count)
   kfcmain.main_ui.tablewidget.setitem(row_count, 0, qtablewidgetitem(activity.activity_ui.label_3.text()))
   kfcmain.main_ui.tablewidget.setitem(row_count, 1, qtablewidgetitem("×" + str(self.bt1)))
   kfcmain.main_ui.tablewidget.setitem(row_count, 2, qtablewidgetitem(str(self.num_act1)))
 else:
  if self.bt1 != 0:
  row_count = kfcmain.main_ui.tablewidget.rowcount()
  kfcmain.main_ui.tablewidget.insertrow(row_count)
  kfcmain.main_ui.tablewidget.setitem(row_count, 0, qtablewidgetitem(activity.activity_ui.label_3.text()))
  kfcmain.main_ui.tablewidget.setitem(row_count, 1, qtablewidgetitem("×" + str(self.bt1)))
  kfcmain.main_ui.tablewidget.setitem(row_count, 2, qtablewidgetitem(str(self.num_act1)))
 
if __name__=="__main__":
 app = qapplication(sys.argv)
 
 kfcmain = kfc_main()
 normal = normal()
 package = package()
 activity = activity()
 # 显示主界面
 kfcmain.person()
 # 绑定按钮
 btn_normal = kfcmain.main_ui.pushbutton_2
 btn_normal.clicked.connect(normal.nor_order)
 btn_package = kfcmain.main_ui.pushbutton_3
 btn_package.clicked.connect(package.pac_order)
 btn_activity = kfcmain.main_ui.pushbutton_4
 btn_activity.clicked.connect(activity.act_order)
 # 初始化name列表
 name = []
 
 sys.exit(app.exec_())

删除只实现了同餐品在订单上的删除,没有实现数量的减少,可自行添加。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/dcjmessi/article/details/83450737