1+ import tkinter as tk
2+ import pickle , os
3+ import datetime as dt
4+
5+ today = dt .datetime .now ()
6+ today_str = today .strftime ("%Y-%m-%d" )
7+
8+ price_meal = {"김밥" : 3000 , "라면" : 3500 , "떡볶이" : 5000 , "튀김" : 5000 , "쫄면" : 7000 }
9+ price_drink = {"콜라" : 1000 , "사이다" : 1000 , "환타" : 1000 , "레몬에이드" : 3000 , "자몽에이드" : 3500 }
10+ # 결제내역 저장 리스트
11+ paylog = []
12+ # 테이블 정보 딕셔너리
13+ table = {}
14+ # 현재 처리 중인 테이블 번호
15+ table_no = ""
16+
17+ # 테이블 선택
18+ def table_select (tno ):
19+ global table_no
20+ table_no = tno
21+
22+ print ("table number:" , tno )
23+ label_table .configure (text = "테이블 " + str (table_no ))
24+
25+ frame5 .pack_forget ()
26+ frame6 .pack_forget ()
27+ print_order ()
28+ print_price ()
29+ show_meal ()
30+
31+
32+ # 테이블 보여줌
33+ def show_table ():
34+ frame1 .pack_forget ()
35+ frame2 .pack_forget ()
36+ frame3 .pack_forget ()
37+ frame4 .pack_forget ()
38+ frame5 .pack (fill = "both" , expand = True )
39+ frame6 .pack_forget ()
40+
41+
42+ # 식사 메뉴 보여줌
43+ def show_meal ():
44+ btn_meal .configure (bg = "yellow" )
45+ btn_drink .configure (bg = "white" )
46+ frame4 .pack_forget ()
47+ frame3 .pack_forget ()
48+ frame6 .pack_forget ()
49+ frame1 .pack (fill = "both" , expand = True )
50+ frame2 .pack (fill = "both" , expand = True )
51+ frame4 .pack (fill = "both" , expand = True )
52+
53+
54+ # 음료 메뉴 보여줌
55+ def show_drink ():
56+ btn_meal .configure (bg = "white" )
57+ btn_drink .configure (bg = "yellow" )
58+ frame4 .pack_forget ()
59+ frame2 .pack_forget ()
60+ frame6 .pack_forget ()
61+ frame1 .pack (fill = "both" , expand = True )
62+ frame3 .pack (fill = "both" , expand = True )
63+ frame4 .pack (fill = "both" , expand = True )
64+
65+
66+ # 식사 주문
67+ def meal_add (m ):
68+ global price_meal , table , table_no , today_str
69+
70+ order_meal = table [table_no ][0 ]
71+ total_price = table [table_no ][2 ]
72+
73+ if m not in price_meal :
74+ print ("입력한 메뉴가 존재하지 않습니다." )
75+ this_price = price_meal .get (m )
76+ total_price += this_price
77+
78+ if m in order_meal :
79+ order_meal [m ] = order_meal .get (m ) + 1
80+ else :
81+ order_meal [m ] = 1
82+
83+ table [table_no ][0 ] = order_meal
84+ table [table_no ][2 ] = total_price
85+ table [table_no ][3 ] = today_str
86+
87+ print_order ()
88+ print_price ()
89+
90+ for i in table :
91+ print (table [i ])
92+ print ()
93+
94+
95+ # 음료 주문
96+ def drink_add (m ):
97+ global price_drink , table , table_no
98+ order_drink = table [table_no ][1 ]
99+ total_price = table [table_no ][2 ]
100+
101+ if m not in price_drink :
102+ print ("입력한 메뉴가 존재하지 않습니다." )
103+ this_price = price_drink .get (m )
104+ total_price += this_price
105+
106+ if m in order_drink :
107+ order_drink [m ] = order_drink .get (m ) + 1
108+ else :
109+ order_drink [m ] = 1
110+
111+ table [table_no ][1 ] = order_drink
112+ table [table_no ][2 ] = total_price
113+ table [table_no ][3 ] = today_str
114+
115+ print_order ()
116+ print_price ()
117+
118+ for i in table :
119+ print (table [i ])
120+ print ()
121+
122+
123+ # 주문내역 화면 출력
124+ def print_order ():
125+ global table , table_no
126+
127+ order_meal = table [table_no ][0 ]
128+ order_drink = table [table_no ][1 ]
129+
130+ tmp = ""
131+ price_tmp = 0
132+ for i in order_meal :
133+ price_tmp = price_meal [i ] * order_meal .get (i )
134+ tmp = tmp + i + " X " + str (order_meal .get (i )) + " = " + str (price_tmp )+ "\n "
135+ for i in order_drink :
136+ price_tmp = price_drink [i ] * order_drink .get (i )
137+ tmp = tmp + i + " X " + str (order_drink .get (i )) + " = " + str (price_tmp )+ "\n "
138+
139+ text_1 .delete ('1.0' , tk .END )
140+ text_1 .insert (tk .INSERT , tmp )
141+
142+
143+ # 주문 완료
144+ def order_end ():
145+ global table_no
146+ table_no = ""
147+
148+ show_table ()
149+
150+
151+ # 상단 금액 출력
152+ def print_price ():
153+ global table , table_no
154+ total_price = table [table_no ][2 ]
155+ label_price .configure (text = str (total_price )+ " 원" )
156+
157+
158+ # 금액 계산
159+ def cal_pay (event ):
160+ global table , table_no
161+ total_price = table [table_no ][2 ]
162+ label_price .configure (text = str (total_price )+ " 원" )
163+ label_total2 .configure (text = str (total_price )+ " 원" )
164+ test = str (entry_pay .get ())
165+ if test == "" :
166+ pay = 0
167+ else :
168+ pay = int (test )
169+
170+ if pay > total_price :
171+ jan = pay - total_price
172+ label_jan2 .configure (text = str (jan )+ " 원" )
173+ else :
174+ label_jan2 .configure (text = "0 원" )
175+
176+
177+ # 결제
178+ def pay ():
179+ frame2 .pack_forget ()
180+ frame3 .pack_forget ()
181+ frame4 .pack_forget ()
182+ frame6 .pack (fill = "both" , expand = True )
183+ cal_pay ('' )
184+
185+
186+ # 결제 완료
187+ def pay_end ():
188+ global table , table_no , paylog , entry_pay
189+ paylog .append (table [table_no ])
190+
191+ with open ("pypos.pickle" , "wb" ) as f :
192+ pickle .dump (paylog , f )
193+
194+ table [table_no ] = [{}, {}, 0 , today_str , table_no ]
195+ table_no = ""
196+ entry_pay .delete ('0' , tk .END )
197+ frame6 .pack_forget ()
198+ show_table ()
199+ today_result ()
200+
201+
202+ # 당일 매출 출력
203+ def today_result ():
204+ global paylog , today_str
205+ result = 0
206+ for i in paylog :
207+ if i [3 ] == today_str :
208+ result += i [2 ]
209+ print ("{} 매출 실적: {}원" .format (today_str , result ))
210+
211+
212+ if os .path .exists ("pypos.pickle" ):
213+ with open ("pypos.pickle" , "rb" ) as f :
214+ paylog = pickle .load (f )
215+
216+ for row in paylog :
217+ print (row )
218+
219+
220+ window = tk .Tk ()
221+ window .title ("PyPOS Ver 0.1" )
222+ window .geometry ("600x400+500+300" )
223+ window .resizable (False , False )
224+
225+ frame1 = tk .Frame (window , width = "600" , height = "10" )
226+ # frame1.pack(fill="both")
227+
228+ frame5 = tk .Frame (window , width = "600" , height = "10" )
229+ frame5 .pack (fill = "both" , expand = True )
230+
231+ frame2 = tk .Frame (window , width = "600" )
232+ # frame2.pack(fill="both", expand=True)
233+
234+ frame3 = tk .Frame (window , width = "600" )
235+ # frame3.pack(fill="both", expand=True)
236+
237+ frame4 = tk .Frame (window , width = "600" , height = "10" )
238+ # frame4.pack(fill="both", expand=True)
239+
240+ frame6 = tk .Frame (window , width = "600" )
241+ # frame6.pack(fill="both", expand=True)
242+
243+
244+ label_table = tk .Label (frame1 , text = "테이블번호 " , padx = 10 , pady = 10 , fg = "red" , font = 'Arial 15' )
245+ label_table .grid (row = 0 , column = 0 , padx = 10 , pady = 10 )
246+
247+ btn_meal = tk .Button (frame1 , text = "식사" , padx = "10" , pady = "10" , bg = "yellow" , command = show_meal )
248+ btn_meal .grid (row = 0 , column = 1 , padx = 10 , pady = 10 )
249+
250+ btn_drink = tk .Button (frame1 , text = "음료" , padx = "10" , pady = "10" , bg = "white" , command = show_drink )
251+ btn_drink .grid (row = 0 , column = 2 , padx = 10 , pady = 10 )
252+
253+ btn_end = tk .Button (frame1 , text = "주문종료" , padx = "10" , pady = "10" , command = order_end )
254+ btn_end .grid (row = 0 , column = 3 , padx = 10 , pady = 10 )
255+
256+ btn_pay = tk .Button (frame1 , text = "결제" , padx = "10" , pady = "10" , command = pay )
257+ btn_pay .grid (row = 0 , column = 4 , padx = 10 , pady = 10 )
258+
259+ label_price = tk .Label (frame1 , text = "0 원" , width = "10" , padx = 10 , pady = "10" , fg = "blue" , font = 'Arial 15' )
260+ label_price .grid (row = 0 , column = 5 , padx = "10" , pady = "10" )
261+
262+ # 식사
263+ btn_meal_1 = tk .Button (frame2 , text = "김밥\n (3000원)" , padx = "10" , pady = "10" , width = "10" , command = lambda : meal_add ('김밥' ))
264+ btn_meal_1 .grid (row = 0 , column = 0 , padx = 10 , pady = 10 )
265+
266+ btn_meal_2 = tk .Button (frame2 , text = "라면\n (3500원)" , padx = "10" , pady = "10" , width = "10" , command = lambda : meal_add ('라면' ))
267+ btn_meal_2 .grid (row = 0 , column = 1 , padx = 10 , pady = 10 )
268+
269+ btn_meal_3 = tk .Button (frame2 , text = "떡볶이\n (5000원)" , padx = "10" , pady = "10" , width = "10" , command = lambda : meal_add ('떡볶이' ))
270+ btn_meal_3 .grid (row = 0 , column = 2 , padx = 10 , pady = 10 )
271+
272+ btn_meal_4 = tk .Button (frame2 , text = "튀김\n (5000원)" , padx = "10" , pady = "10" , width = "10" , command = lambda : meal_add ('튀김' ))
273+ btn_meal_4 .grid (row = 0 , column = 3 , padx = 10 , pady = 10 )
274+
275+ btn_meal_5 = tk .Button (frame2 , text = "쫄면\n (7000원)" , padx = "10" , pady = "10" , width = "10" , command = lambda : meal_add ('쫄면' ))
276+ btn_meal_5 .grid (row = 0 , column = 4 , padx = 10 , pady = 10 )
277+
278+
279+ # 음료
280+ btn_drink_1 = tk .Button (frame3 , text = "콜라\n (1000원)" , padx = "10" , pady = "10" , width = "10" , command = lambda : drink_add ('콜라' ))
281+ btn_drink_1 .grid (row = 0 , column = 0 , padx = 10 , pady = 10 )
282+
283+ btn_drink_2 = tk .Button (frame3 , text = "사이다\n (1000원)" , padx = "10" , pady = "10" , width = "10" , command = lambda : drink_add ('사이다' ))
284+ btn_drink_2 .grid (row = 0 , column = 1 , padx = 10 , pady = 10 )
285+
286+ btn_drink_3 = tk .Button (frame3 , text = "환타\n (1000원)" , padx = "10" , pady = "10" , width = "10" , command = lambda : drink_add ('환타' ))
287+ btn_drink_3 .grid (row = 0 , column = 2 , padx = 10 , pady = 10 )
288+
289+ btn_drink_4 = tk .Button (frame3 , text = "레몬에이드\n (3000원)" , padx = "10" , pady = "10" , width = "10" , command = lambda : drink_add ('레몬에이드' ))
290+ btn_drink_4 .grid (row = 0 , column = 3 , padx = 10 , pady = 10 )
291+
292+ btn_drink_5 = tk .Button (frame3 , text = "자몽에이드\n (3500원)" , padx = "10" , pady = "10" , width = "10" , command = lambda : drink_add ('자몽에이드' ))
293+ btn_drink_5 .grid (row = 0 , column = 4 , padx = 10 , pady = 10 )
294+
295+ # 테이블
296+ btn_table_1 = tk .Button (frame5 , text = "테이블 1" , padx = "10" , pady = "10" , width = "10" , command = lambda : table_select (1 ))
297+ btn_table_1 .grid (row = 0 , column = 0 , padx = 20 , pady = 20 )
298+
299+ btn_table_2 = tk .Button (frame5 , text = "테이블 2" , padx = "10" , pady = "10" , width = "10" , command = lambda : table_select (2 ))
300+ btn_table_2 .grid (row = 0 , column = 1 , padx = 20 , pady = 20 )
301+
302+ btn_table_3 = tk .Button (frame5 , text = "테이블 3" , padx = "10" , pady = "10" , width = "10" , command = lambda : table_select (3 ))
303+ btn_table_3 .grid (row = 0 , column = 2 , padx = 20 , pady = 20 )
304+
305+ btn_table_4 = tk .Button (frame5 , text = "테이블 4" , padx = "10" , pady = "10" , width = "10" , command = lambda : table_select (4 ))
306+ btn_table_4 .grid (row = 0 , column = 3 , padx = 20 , pady = 20 )
307+
308+ btn_table_5 = tk .Button (frame5 , text = "테이블 5" , padx = "10" , pady = "10" , width = "10" , command = lambda : table_select (5 ))
309+ btn_table_5 .grid (row = 1 , column = 0 , padx = 20 , pady = 20 )
310+
311+ btn_table_6 = tk .Button (frame5 , text = "테이블 6" , padx = "10" , pady = "10" , width = "10" , command = lambda : table_select (6 ))
312+ btn_table_6 .grid (row = 1 , column = 1 , padx = 20 , pady = 20 )
313+
314+ btn_table_7 = tk .Button (frame5 , text = "테이블 7" , padx = "10" , pady = "10" , width = "10" , command = lambda : table_select (7 ))
315+ btn_table_7 .grid (row = 1 , column = 2 , padx = 20 , pady = 20 )
316+
317+ btn_table_8 = tk .Button (frame5 , text = "테이블 8" , padx = "10" , pady = "10" , width = "10" , command = lambda : table_select (8 ))
318+ btn_table_8 .grid (row = 1 , column = 3 , padx = 20 , pady = 20 )
319+
320+ # 주문 리스트
321+ text_1 = tk .Text (frame4 , height = "10" )
322+ text_1 .pack ()
323+
324+ # 결제(금액, 내신돈, 받으실돈)
325+ label_total = tk .Label (frame6 , text = "결제금액" , padx = 10 , pady = "3" , font = 'Arial 15' )
326+ label_total .grid (row = 0 , column = 0 , padx = "10" , pady = "3" )
327+
328+ label_total2 = tk .Label (frame6 , text = "0원" , padx = 10 , pady = "3" , font = 'Arial 15' )
329+ label_total2 .grid (row = 0 , column = 1 , padx = "10" , pady = "3" )
330+
331+ label_pay = tk .Label (frame6 , text = "내신돈" , padx = 10 , pady = "3" , font = 'Arial 15' )
332+ label_pay .grid (row = 1 , column = 0 , padx = "10" , pady = "3" )
333+
334+ entry_pay = tk .Entry (frame6 , width = 10 , font = 'Arial 15' )
335+ entry_pay .insert ('0' , "" )
336+ entry_pay .bind ("<Return>" , cal_pay )
337+ entry_pay .grid (row = 1 , column = 1 , padx = "10" , pady = "3" )
338+
339+ label_jan = tk .Label (frame6 , text = "받으실돈" , padx = 10 , pady = "3" , font = 'Arial 15' )
340+ label_jan .grid (row = 2 , column = 0 , padx = "10" , pady = "3" )
341+
342+ label_jan2 = tk .Label (frame6 , text = "0원" , padx = 10 , pady = "10" , font = 'Arial 15' )
343+ label_jan2 .grid (row = 2 , column = 1 , padx = "10" , pady = "3" )
344+
345+ btn_payend = tk .Button (frame6 , text = "결제 완료" , padx = "10" , pady = "10" , command = pay_end )
346+ btn_payend .grid (row = 3 , column = 0 , padx = 10 , pady = 10 )
347+
348+
349+ # 테이블 세팅
350+ for i in range (1 , 9 ):
351+ table [i ] = [{}, {}, 0 , today_str , i ]
352+
353+ window .mainloop ()
0 commit comments