파이썬 질문 드립니다ㅠㅠㅠ
본문
왕초보가 구글링 해가면서 최대한 코드를 짰는데 실행을 하고 버튼을 누르면 아래처럼 오류가 뜨고 아무것도 프린트 되지 않습니다ㅜㅜㅜㅜ
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\ㅡㅡㅡ\anaconda3\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
TypeError: ice_add() missing 1 required positional argument: 'm'
어떤 것이 잘못된 건가요?ㅠㅠㅠㅠㅠㅠㅠㅠㅠ
그리고 더불어 프로그램을 실행했을 때 창 안의 버튼들이 두서없이 너무 띄어져 있는데 이 부분도 한번 봐주시면 감사하겠습니다!!!!
import tkinter as tk price_in_out={'매장':0,'포장':0} price_ice={'Regular Ice':0,'Full Ice':0,'Less Ice':0} price_sugar={'100%':0,'70%':0,'30%':0,'0%':0} price_topping={'타피오카펄':500,'알로에':500,'코코넛':600,'치즈폼':700,'딸기쥬얼리':900} order_in_out={} order_ice={} order_sugar={} order_topping={} total_price=0 def in_out_add(m): global price_in_out,order_in_out,total_price if m not in price_in_out: print("입력한 메뉴가 존재하지 않습니다.") this_price=price_in_out.get(m) total_price+=this_price if m in order_in_out: order_in_out[m]=order_in_out.get(m)+1 else: order_in_out[m]=1 print_order() print_price() def ice_add(m): global price_ice,order_ice,total_price if m not in price_ice: print("입력한 메뉴가 존재하지 않습니다.") this_price=price_ice.get(m) total_price+=this_price if m in order_ice: order_ice[m]=order_ice.get(m)+1 else: order_ice[m]=1 print_order() print_price() def sugar_add(m): global price_sugar,order_sugar,total_price if m not in price_sugar: print("입력한 메뉴가 존재하지 않습니다.") this_price=price_sugar.get(m) total_price+=this_price if m in order_sugar: order_sugar[m]=order_sugar.get(m)+1 else: order_sugar[m]=1 print_order() print_price() def topping_add(m): global price_topping,order_topping,total_price if m not in price_topping: print("입력한 메뉴가 존재하지 않습니다.") this_price=price_topping.get(m) total_price+=this_price if m in order_topping: order_topping[m]=order_topping.get(m)+1 else: order_topping[m]=1 print_order() print_price() def print_order(): global order_in_out, order_ice, order_sugar,order_topping tmp="" for i in order_in_out: tmp=tmp+i+"X"+str(order_in_out.get(i))+"\n" for i in order_ice: tmp=tmp+i+"X"+str(order_ice.get(i))+"\n" for i in order_sugar: tmp=tmp+i+"X"+str(order_sugar.get(i))+"\n" for i in order_topping: tmp=tmp+i+"X"+str(order_topping.get(i))+"\n" text_1.delete('1.0',tk.END) text_1.insert(tk.INSERT,tmp) def order_end(): global total_price, order_in_out, order_ice, order_sugar,order_topping total_price=0 del order_in_out del order_ice del order_sugar del order_topping order_in_out={} order_ice={} order_sugar={} order_topping={} print_price() print_order() #show_drink() def print_price(): global total_price label_price.configure(text=str(total_price)+"원") ##메인 코드 부분 window=tk.Tk() window.title("추가 주문 사항") window.geometry("430x600+500+20") window.resizable() #False,False frame1=tk.Frame(window,width="600",height="10") frame1.pack(fill="both") frame2=tk.Frame(window,width="600") frame2.pack(fill="both",expand=True) frame3=tk.Frame(window,width="600",height="10") #frame3.pack(fill="both", expand=True) frame4=tk.Frame(window,width="600",height="10") frame4.pack(fill="both",expand=True) btn_end=tk.Button(frame1,text="주문하기",padx="10",pady="10",command=order_end) btn_end.grid(row=6,column=1,padx=10,pady=10) label_price=tk.Label(frame1,text="0원",width="20",padx=10 ,pady="10",font='Arial 15') label_price.grid(row=5,column=1,padx=10,pady=10) btn_in_out=tk.Button(frame1,text="포장",padx="10",pady="10",command=in_out_add) btn_in_out.grid(row=0,column=0,padx=10,pady=10) btn_in_out1=tk.Button(frame1,text="매장",padx="10",pady="10",command=in_out_add) btn_in_out1.grid(row=0,column=1,padx=10,pady=10) btn_ice1=tk.Button(frame1,text="Less Ice",padx="10",pady="10",command=ice_add) btn_ice1.grid(row=1,column=0,padx=10,pady=10) btn_ice2=tk.Button(frame1,text="Regular Ice",padx="10",pady="10", command=ice_add) btn_ice2.grid(row=1,column=1,padx=10,pady=10) btn_ice3=tk.Button(frame1, text="Full Ice",padx="10",pady="10", command=ice_add) btn_ice3.grid(row=1,column=2,padx=10,pady=10) btn_sugar1=tk.Button(frame1,text="30%",padx="10",pady="10", command=sugar_add) btn_ice3.grid(row=2,column=0,padx=10,pady=10) btn_sugar2=tk.Button(frame1,text="50%",padx="10",pady="10", command=sugar_add) btn_sugar2.grid(row=2,column=1,padx=10,pady=10) btn_sugar3=tk.Button(frame1,text="70%",padx="10",pady="10", command=sugar_add) btn_sugar3.grid(row=2,column=2,padx=10,pady=10) btn_sugar4=tk.Button(frame1,text="100%",padx="10",pady="10", command=sugar_add) btn_sugar4.grid(row=2,column=3,padx=10,pady=10) btn_topping1=tk.Button(frame1,text="타피오카펄",padx="10",pady="10", command=topping_add) btn_topping1.grid(row=3,column=0,padx=10,pady=10) btn_topping2=tk.Button(frame1,text="알로에",padx="10",pady="10", command=topping_add) btn_topping2.grid(row=3,column=1,padx=10,pady=10) btn_topping3=tk.Button(frame1,text="코코넛",padx="10",pady="10", command=topping_add) btn_topping3.grid(row=3,column=2,padx=10,pady=10) btn_topping4=tk.Button(frame1,text="치즈폼",padx="10",pady="10", command=topping_add) btn_topping4.grid(row=3,column=3,padx=10,pady=10) btn_topping5=tk.Button(frame1,text="딸기쥬얼리",padx="10",pady="10", command=topping_add) btn_topping5.grid(row=4,column=0,padx=10,pady=10) #주문 리스트 text_1=tk.Text(frame4,height="10") text_1.pack() window.mainloop()
답변 2
lambda 를 사용해야 합니다.
btn_ice1=tk.Button(frame1,text="Less Ice", command=lambda: ice_add(m))
btn_ice1.grid(row=1,column=0,padx=10,pady=10)
https://stackoverflow.com/questions/5767228/why-is-button-parameter-command-executed-when-declared
참고해보세요.
ice_add( m) 여기 파라미터가 안들어가 있네요
btn_ice1=tk.Button(frame1,text="Less Ice",padx="10",pady="10",command=ice_add)
답변을 작성하시기 전에 로그인 해주세요.