私はプログラミングに非常に慣れていないため、顧客が選択した調味料とともに、顧客が望んでいるパンの種類を印刷する必要があるという問題があります。テキストボックスで選択/チェックした項目を印刷する方法がわかりません。これは私がこれまでに持っているものです。
from Tkinter import *
class Application(Frame):
def __init__ (self, master):
Frame.__init__(self, master)
self.grid()
self.create_widget()
def create_widget(self):
self.lbl = Label(self, text="Place your order").grid(row=0,column=2,columnspan=4)
self.lbl2 = Label(self, text="Customer Name:").grid(row=1,column=0,columnspan=4,sticky=W)
self.lbl3 = Label(self, text="Select your bun:").grid(row=2, column =0, columnspan=3, sticky=W)
self.lbl4 = Label(self, text="Condiments:").grid(row=3, column =0, columnspan=3, sticky=W)
self.bun = StringVar()
self.bun.set(None)
self.radio_bttn = Radiobutton(self, text = "White", variable = self.bun, value=1).grid(row=2, column = 1, columnspan=4)
self.radio_bttn2 = Radiobutton(self, text = "Wheat", variable = self.bun, value=2).grid(row=2, column= 2, columnspan=4)
self.work = Text(self,width=50,height=5).grid(row=12, column = 0, columnspan = 6)
self.work1 = Text(self,width=40,height=1).grid(row=1,column=3, columnspan=4)
self.cheese = BooleanVar()
Checkbutton(self, text="Cheese", variable=self.cheese, onvalue="yes", offvalue="no").grid(row=4, column=0, sticky = W)
self.lettuce = BooleanVar()
Checkbutton(self, text="Lettuce", variable=self.lettuce, onvalue="yes", offvalue="no").grid(row=5, column=0, sticky = W)
self.onion = BooleanVar()
Checkbutton(self, text="Onion", variable=self.onion, onvalue="yes", offvalue="no").grid(row=6, column=0, sticky = W)
self.tomato = BooleanVar()
Checkbutton(self, text="Tomato", variable=self.tomato, onvalue="yes", offvalue="no").grid(row=7, column=0, sticky = W)
self.pickles = BooleanVar()
Checkbutton(self, text="Pickles", variable=self.pickles, onvalue="yes", offvalue="no").grid(row=8, column=0, sticky = W)
self.mustard = BooleanVar()
Checkbutton(self, text="Mustard", variable=self.mustard, onvalue="yes", offvalue="no").grid(row=9, column=0, sticky = W)
self.mayo = BooleanVar()
Checkbutton(self, text="Mayo", variable=self.mayo, onvalue="yes", offvalue="no").grid(row=10, column=0, sticky = W)
self.ketchup = BooleanVar()
Checkbutton(self, text="Ketchup", variable=self.ketchup, onvalue="yes", offvalue="no").grid(row=11, column=0, sticky = W)
self.bttn_bttn = Button(self, text="Order", command = callback).grid(row =13, column = 0, sticky = W)
def callback(self):
toppings = "Here are your toppings.\n"
if self.cheese.get():
toppings += "Cheese\n"
if self.lettuce.get():
toppings += "Lettuce\n"
if self.onion.get():
toppings += "Onion\n"
if self.tomato.get():
toppings += "Tomato\n"
if self.pickles.get():
toppings += "Pickles\n"
if self.mustard.get():
toppings += "Mustard\n"
if self.mayo.get():
toppings += "Mayo\n"
if self.ketchup.get():
toppings += "Ketchup\n"
self.work.insert(0.0, toppings)
#main
root= Tk()
root.title("Burger")
root.geometry("400x500")
app = Application(root)
root.mainloop(