Skip to content

Commit 9ca3666

Browse files
authored
Create tkinter_coffee_machine.py
1 parent f900cc8 commit 9ca3666

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

tkinter_coffee_machine.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import tkinter as tk
2+
from tkinter import messagebox
3+
4+
def center(toplevel):
5+
toplevel.update_idletasks()
6+
w = toplevel.winfo_screenwidth()
7+
h = toplevel.winfo_screenheight()
8+
size = tuple(int(_) for _ in toplevel.geometry().split('+')[0].split('x'))
9+
x = w / 2 - size[0] / 2
10+
y = h / 2 - size[1] / 2
11+
toplevel.geometry("%dx%d+%d+%d" % (size + (x, y)))
12+
13+
14+
def add():
15+
global c1Var, c2Var, c3Var, c4Var
16+
sum = 0
17+
order = ""
18+
19+
if c1Var.get() == 1:
20+
sum += 3000
21+
order += "아메리카노/"
22+
if c2Var.get() == 1:
23+
sum += 4000
24+
order += "카페라떼/"
25+
if c3Var.get() == 1:
26+
sum += 4000
27+
order += "카프치노/"
28+
if c4Var.get() == 1:
29+
sum += 5000
30+
order += "에스프레소/"
31+
label1['text'] = "금액: " + str(sum) + "원"
32+
label2['text'] = "선택: " + order
33+
34+
35+
def btn_exit():
36+
msgbox = tk.messagebox.askquestion('확인','주문을 마치시겠습니까?')
37+
if msgbox == 'yes':
38+
exit()
39+
40+
41+
window = tk.Tk()
42+
window.title("커피자판기")
43+
window.geometry("300x400")
44+
# center(window)
45+
46+
frame1 = tk.Frame(window)
47+
frame1.pack()
48+
tk.Label(window, text="커피자판기")
49+
50+
label0 = tk.Label(window, text="커피자판기", width=100, height=2, font="Arial 15")
51+
label0.pack()
52+
53+
c1Var = tk.IntVar()
54+
c2Var = tk.IntVar()
55+
c3Var = tk.IntVar()
56+
c4Var = tk.IntVar()
57+
58+
c1 = tk.Checkbutton(window, text="아메리카노 - 3000원", variable=c1Var, command=add)
59+
c2 = tk.Checkbutton(window, text="카페라떼 - 4000원", variable=c2Var, command=add)
60+
c3 = tk.Checkbutton(window, text="카프치노 - 4000원", variable=c3Var, command=add)
61+
c4 = tk.Checkbutton(window, text="에스프레소 - 5000원", variable=c4Var, command=add)
62+
63+
c1.pack()
64+
c2.pack()
65+
c3.pack()
66+
c4.pack()
67+
68+
label1 = tk.Label(window, text="금액: 0원", width=100, height=2, pady="20")
69+
label1.pack()
70+
71+
label2 = tk.Label(window, text="선택음료", width=100, height=2)
72+
label2.pack()
73+
74+
window.mainloop()

0 commit comments

Comments
 (0)