키오스크 프로그램(Tkinter)
2024. 5. 13. 21:01ㆍpython study/tkinter study & project
최종 코드
from tkinter import *
from tkinter import font
root = Tk()
root.title("햄버거 주문 키오스크")
root.geometry("612x700")
font_style = font.Font(family="굴림체", size=12)
root.minsize(width=612, height=700)
root.maxsize(width=612, height=700)
photo1 = PhotoImage(file="더블.png")
photo2 = PhotoImage(file="모짜.png")
photo3 = PhotoImage(file="빅불.png")
photo4 = PhotoImage(file="찐빙수.png")
photo5 = PhotoImage(file="치즈스틱.png")
photo6 = PhotoImage(file="치즈에그.png")
a1 = IntVar()
a2 = IntVar()
a3 = IntVar()
a4 = IntVar()
a5 = IntVar()
a6 = IntVar()
total_price=0
total_price_side=0
def delete():
total_price=0
total_price_side=0
ent.delete(0, END)
ent2.delete(0, END)
ent3.delete(0, END)
a1.set(0)
a2.set(0)
a3.set(0)
a4.set(0)
a5.set(0)
a6.set(0)
def end():
root.destroy()
def total():
global total_price
ent.delete(0, END)
if a1.get() == 1 and a2.get() == 0 and a3.get() == 0:
total_price = 7500
elif a1.get() == 0 and a2.get() == 1 and a3.get() == 0:
total_price = 7700
elif a1.get() == 0 and a2.get() == 0 and a3.get() == 1:
total_price = 7600
elif a1.get() == 1 and a2.get() == 1 and a3.get() == 0:
total_price = 7500 + 7700
elif a1.get() == 1 and a2.get() == 0 and a3.get() == 1:
total_price = 7500 + 7600
elif a1.get() == 0 and a2.get() == 1 and a3.get() == 1:
total_price = 7700 + 7600
elif a1.get() == 1 and a2.get() == 1 and a3.get() == 1:
total_price = 7500 + 7700 + 7600
else:
total_price=0
ent.insert(0, total_price)
def total2():
global total_price_side
ent2.delete(0, END)
if a4.get() == 1 and a5.get() == 0 and a6.get() == 0:
total_price_side = 3800
elif a4.get() == 0 and a5.get() == 1 and a6.get() == 0:
total_price_side = 1800
elif a4.get() == 0 and a5.get() == 0 and a6.get() == 1:
total_price_side = 3000
elif a4.get() == 1 and a5.get() == 1 and a6.get() == 0:
total_price_side = 3800 + 1800
elif a4.get() == 1 and a5.get() == 0 and a6.get() == 1:
total_price_side = 3800 + 3000
elif a4.get() == 0 and a5.get() == 1 and a6.get() == 1:
total_price_side = 1800 + 3000
elif a4.get() == 1 and a5.get() == 1 and a6.get() == 1:
total_price_side = 3800 + 1800 + 3000
else:
total_price_side=0
ent2.insert(0, total_price_side)
def total3():
ent3.delete(0, END)
if a1.get() == 0 and a2.get() == 0 and a3.get() == 0 and a4.get() == 0 and a5.get() == 0 and a6.get() == 0:
ent3.delete(0, END)
elif a1.get() == 0 and a2.get() == 0 and a3.get() == 0:
ent3.insert(0, total_price_side)
elif a4.get() == 0 and a5.get() == 0 and a6.get() == 0:
ent3.insert(0, total_price)
else:
total_price_final = total_price + total_price_side
ent3.insert(0, total_price_final)
ent=Entry(root, font=font_style)
ent.grid(row=9, column=2)
ent2=Entry(root, font=font_style)
ent2.grid(row=10, column=2)
ent3=Entry(root, font=font_style)
ent3.grid(row=11, column=2)
chb1=Checkbutton(root, text="더블 X2 세트", font=font_style, variable=a1, command=total)
chb1.grid(row=1, column=0)
lbl3=Label(root, image=photo1)
lbl3.grid(row=2, column=0)
chb2=Checkbutton(root, text="모짜렐라 베이컨 세트", font=font_style, variable=a2, command=total)
chb2.grid(row=1, column=1)
lbl4=Label(root, image=photo2)
lbl4.grid(row=2, column=1)
chb3=Checkbutton(root, text="원조 빅불 세트", font=font_style, variable=a3, command=total)
chb3.grid(row=1, column=2)
lbl5=Label(root, image=photo3)
lbl5.grid(row=2, column=2)
chb4=Checkbutton(root, text="빙수", font=font_style, variable=a4, command=total2)
chb4.grid(row=4, column=0)
lbl6=Label(root, image=photo4)
lbl6.grid(row=5, column=0)
chb5=Checkbutton(root, text="치즈 스틱", font=font_style, variable=a5, command=total2)
chb5.grid(row=4, column=1)
lbl7=Label(root, image=photo5)
lbl7.grid(row=5, column=1)
chb6=Checkbutton(root, text="치즈인더에그", font=font_style, variable=a6, command=total2)
chb6.grid(row=4, column=2)
lbl8=Label(root, image=photo6)
lbl8.grid(row=5, column=2)
btn=Button(root, text="계산하기", width=11, height=2, bg="gray", fg="white", font=font_style, command=total3)
btn.grid(row=13, column=1)
btn2=Button(root, text="지우기", width=11, height=2, bg="gray", fg="white", font=font_style, command=delete)
btn2.grid(row=13, column=2)
btn3=Button(root, text="종료하기", width=11, height=2, bg="gray", fg="white", font=font_style, command=end)
btn3.place(x=519, y=652)
lbl9=Label(root, text=" ", font=font_style)
lbl9.grid(row=12, column=1)
lbl9=Label(root, text=" ", font=font_style)
lbl9.grid(row=12, column=2)
lbl10=Label(root, text="[햄버거 세트]", font=font_style)
lbl10.grid(row=9, column=1)
lbl10=Label(root, text="[사이드 메뉴]", font=font_style)
lbl10.grid(row=10, column=1)
lbl10=Label(root, text="[최종 가격]", font=font_style)
lbl10.grid(row=11, column=1)
lbld=Label(root, text="[주문 내역]", font=font_style)
lbld.place(x=10, y=550)
lbld=Label(root, text="", font="red")
lbld.place(x=10, y=580)
lbld=Label(root, text="", font="red")
lbld.place(x=10, y=605)
root.mainloop()
꽤 코드가 길지만 함수를 위주로 본다면 굉장히 간단한 코드다.
from tkinter import *
from tkinter import font
root = Tk()
root.title("햄버거 주문 키오스크")
root.geometry("612x700")
font_style = font.Font(family="굴림체", size=12)
root.minsize(width=612, height=700)
root.maxsize(width=612, height=700)
photo1 = PhotoImage(file="더블.png")
photo2 = PhotoImage(file="모짜.png")
photo3 = PhotoImage(file="빅불.png")
photo4 = PhotoImage(file="찐빙수.png")
photo5 = PhotoImage(file="치즈스틱.png")
photo6 = PhotoImage(file="치즈에그.png")
a1 = IntVar()
a2 = IntVar()
a3 = IntVar()
a4 = IntVar()
a5 = IntVar()
a6 = IntVar()
- font_style: 기본적으로 굴림체로 설정하고 사이즈를 12로 지정해 준다.
- minsize, maxsize: 말 그대로 최소 사이즈와 최대 사이즈를 지정하였는데, 위의 코드는 최대 최소를 똑같이 하여서 창의 크기를 고정해주었다.
- PhotoImage: 사진은 PhotoImage를 이용하여서 불러오는데, 여기서 주의할 부분은 파이썬 소스와 이미지가 같은 파일 내부에 있어야 불러올 수 있다.
- 변수 설정: 나중에 체크 버튼을 사용하기 위해서 변수를 설정해 주었다.
def delete():
total_price=0
total_price_side=0
ent.delete(0, END)
ent2.delete(0, END)
ent3.delete(0, END)
a1.set(0)
a2.set(0)
a3.set(0)
a4.set(0)
a5.set(0)
a6.set(0)
def end():
root.destroy()
- delete함수는 Entry박스를 초기화시켜주고 buttoncheck의 변수들도 꺼줌으로써 초기화한다.
- end함수는 종료를 담당한다.
def total():
global total_price
ent.delete(0, END)
if a1.get() == 1 and a2.get() == 0 and a3.get() == 0:
total_price = 7500
elif a1.get() == 0 and a2.get() == 1 and a3.get() == 0:
total_price = 7700
elif a1.get() == 0 and a2.get() == 0 and a3.get() == 1:
total_price = 7600
elif a1.get() == 1 and a2.get() == 1 and a3.get() == 0:
total_price = 7500 + 7700
elif a1.get() == 1 and a2.get() == 0 and a3.get() == 1:
total_price = 7500 + 7600
elif a1.get() == 0 and a2.get() == 1 and a3.get() == 1:
total_price = 7700 + 7600
elif a1.get() == 1 and a2.get() == 1 and a3.get() == 1:
total_price = 7500 + 7700 + 7600
else:
total_price=0
ent.insert(0, total_price)
def total2():
global total_price_side
ent2.delete(0, END)
if a4.get() == 1 and a5.get() == 0 and a6.get() == 0:
total_price_side = 3800
elif a4.get() == 0 and a5.get() == 1 and a6.get() == 0:
total_price_side = 1800
elif a4.get() == 0 and a5.get() == 0 and a6.get() == 1:
total_price_side = 3000
elif a4.get() == 1 and a5.get() == 1 and a6.get() == 0:
total_price_side = 3800 + 1800
elif a4.get() == 1 and a5.get() == 0 and a6.get() == 1:
total_price_side = 3800 + 3000
elif a4.get() == 0 and a5.get() == 1 and a6.get() == 1:
total_price_side = 1800 + 3000
elif a4.get() == 1 and a5.get() == 1 and a6.get() == 1:
total_price_side = 3800 + 1800 + 3000
else:
total_price_side=0
ent2.insert(0, total_price_side)
def total3():
ent3.delete(0, END)
if a1.get() == 0 and a2.get() == 0 and a3.get() == 0 and a4.get() == 0 and a5.get() == 0 and a6.get() == 0:
ent3.delete(0, END)
elif a1.get() == 0 and a2.get() == 0 and a3.get() == 0:
ent3.insert(0, total_price_side)
elif a4.get() == 0 and a5.get() == 0 and a6.get() == 0:
ent3.insert(0, total_price)
else:
total_price_final = total_price + total_price_side
ent3.insert(0, total_price_final)
#entry 박스
ent=Entry(root, font=font_style)
ent.grid(row=9, column=2)
ent2=Entry(root, font=font_style)
ent2.grid(row=10, column=2)
ent3=Entry(root, font=font_style)
ent3.grid(row=11, column=2)
#메뉴들을 체크해주는 checkbutton
chb1=Checkbutton(root, text="더블 X2 세트", font=font_style, variable=a1, command=total)
chb1.grid(row=1, column=0)
lbl3=Label(root, image=photo1)
lbl3.grid(row=2, column=0)
chb2=Checkbutton(root, text="모짜렐라 베이컨 세트", font=font_style, variable=a2, command=total)
chb2.grid(row=1, column=1)
lbl4=Label(root, image=photo2)
lbl4.grid(row=2, column=1)
chb3=Checkbutton(root, text="원조 빅불 세트", font=font_style, variable=a3, command=total)
chb3.grid(row=1, column=2)
lbl5=Label(root, image=photo3)
lbl5.grid(row=2, column=2)
chb4=Checkbutton(root, text="빙수", font=font_style, variable=a4, command=total2)
chb4.grid(row=4, column=0)
lbl6=Label(root, image=photo4)
lbl6.grid(row=5, column=0)
chb5=Checkbutton(root, text="치즈 스틱", font=font_style, variable=a5, command=total2)
chb5.grid(row=4, column=1)
lbl7=Label(root, image=photo5)
lbl7.grid(row=5, column=1)
chb6=Checkbutton(root, text="치즈인더에그", font=font_style, variable=a6, command=total2)
chb6.grid(row=4, column=2)
lbl8=Label(root, image=photo6)
lbl8.grid(row=5, column=2)
#다음 행동을 선택하는 button
btn=Button(root, text="계산하기", width=11, height=2, bg="gray", fg="white", font=font_style, command=total3)
btn.grid(row=13, column=1)
btn2=Button(root, text="지우기", width=11, height=2, bg="gray", fg="white", font=font_style, command=delete)
btn2.grid(row=13, column=2)
btn3=Button(root, text="종료하기", width=11, height=2, bg="gray", fg="white", font=font_style, command=end)
btn3.place(x=519, y=652)
lbl9=Label(root, text=" ", font=font_style)
lbl9.grid(row=12, column=1)
lbl9=Label(root, text=" ", font=font_style)
lbl9.grid(row=12, column=2)
lbl10=Label(root, text="[햄버거 세트]", font=font_style)
lbl10.grid(row=9, column=1)
lbl10=Label(root, text="[사이드 메뉴]", font=font_style)
lbl10.grid(row=10, column=1)
lbl10=Label(root, text="[최종 가격]", font=font_style)
lbl10.grid(row=11, column=1)
lbld=Label(root, text="[주문 내역]", font=font_style)
lbld.place(x=10, y=550)
lbld=Label(root, text="", font="red")
lbld.place(x=10, y=580)
lbld=Label(root, text="", font="red")
lbld.place(x=10, y=605)
root.mainloop()
- 이제 다음부터는 Entry, Checkbutton, image, 택스트 배치를 해준다면 우리가 키오스크에서 보는 화면을 만들 수 있습니다.
