ich bin ein Schüler und bin gerade dabei ein Auswahlmenü mit einem GUI Tkinter Interface zu programmieren. Der erste Code, ist der Code, so wie das programm hinterher laufen soll und welches ich mir zur hilfe nehme, und beim zweiten Code weiß ich nicht wo der felhler liegt. Vielen dank schon mal im Voraus für ihre Unterstützung.
1. Code
Code: Alles auswählen
destination = input("Enter your destination (Edinburgh or Cardiff): ")
travelclass= input("Enter your class (business or economy): ")
meal = input("Do you want on-bord meal(yes or no)? ")
ticket = input("One way or with return(One way or return)? ")
price = 0.00
if destination == "Edinburgh":
if travelclass == "business":
if ticket == "return":
price = 178
elif ticket == "One way":
price = 87
elif travelclass == "economy":
if ticket == "return":
if meal == "yes":
price = 52 + 18
elif meal == "no":
price = 52
elif ticket == "One way":
if meal == "yes":
price = 32 + 12
elif meal == "no":
price = 32
price = 5
elif destination == "Cardiff":
if travelclass == "business":
if ticket == "return":
price = 138
elif ticket == "One way":
price = 72
elif travelclass == "economy":
if ticket == "return":
if meal == "yes":
price = 50 + 18
elif meal == "no":
price = 50
elif ticket == "One way":
if meal == "yes":
price = 36 + 12
elif meal == "no":
price = 36
print("Your travel costs", price, "£")
Code: Alles auswählen
from tkinter import*
window=Tk()
window.title = "Train booking"
price = 0.00
destination_label = Label(window, width=30, height=1, text="To")
destination_label.grid(row=0, column=1)
travelclass_label = Label(window, width=30, height=1, text="Business or economy class")
travelclass_label.grid(row=3, column=1)
meal_label = Label(window, width=30, height=1, text="Do you want meal?")
meal_label.grid(row=6, column=1)
ticket_label = Label(window, width=30, height=1, text="One way or with return?")
ticket_label.grid(row=9, column=1)
destination = StringVar()
edinburgh = Radiobutton(window, text="Edinburgh", variable = destination, value = "Edinburgh")
edinburgh.grid(row=1, column=1)
edinburgh.select()
cardiff = Radiobutton(window, text="Cardiff", variable = destination, value = "Cardiff")
cardiff.grid(row=2, column=1)
travelclass = StringVar()
businessclass = Radiobutton(window, text="Businessclass", variable = travelclass, value = "Businessclass")
businessclass.grid(row=4, column=1)
businessclass.select()
economyclass = Radiobutton(window, text="Economyclass", variable = travelclass, value = "Economyclass")
economyclass.grid(row=5, column=1)
meal = StringVar()
yes_meal = Radiobutton(window, text="Yes", variable = meal, value = "Yes")
yes_meal.grid(row=7, column=1)
yes_meal.select()
no_meal = Radiobutton(window, text="No", variable = meal, value = "No")
no_meal.grid(row=8, column=1)
ticket = StringVar()
return_ticket = Radiobutton(window, text="Return", variable = ticket, value = "Return")
return_ticket.grid(row=10, column=1)
return_ticket.select()
one_way_ticket = Radiobutton(window, text="One way", variable = ticket, value = "One way")
one_way_ticket.grid(row=11, column=1)
def change_text(return_ticket, one_way_ticket, no_meal, yes_meal, economyclass, businessclass, cardiff, edinburgh):
if destination == "Edinburgh":
if travelclass == "Business":
if ticket() == "Return":
price = 178
elif ticket() == "One way":
price = 87
elif travelclass == "Economy":
if ticket() == "Return":
if meal == "Yes":
price = 52 + 18
elif meal == "No":
price = 52
elif ticket() == "One way":
if meal == "Yes":
price = 32 + 12
elif meal == "No":
price = 32
elif destination == "Cardiff":
if travelclass == "Business":
if ticket == "Return":
price = 138
elif ticket == "One way":
price = 72
elif travelclass == "Economy":
if ticket == "Return":
if meal == "Yes":
price = 50 + 18
elif meal == "No":
price = 50
elif ticket == "One way":
if meal == "Yes":
price = 36 + 12
elif meal == "No":
price = 36
submit = Button(window, text="Submit", width=10, bg="red", command=change_text(return_ticket, one_way_ticket, no_meal, yes_meal, economyclass, businessclass, cardiff, edinburgh))
submit.grid(row=12, column=1)
total_costs = Label(window, width=30, height=1, text= ("Your travel costs", price, "£"))
total_costs.grid(row=13, column=1)
window.mainloop()