この単純なプログラムをコーディングしたばかりですが、Tkinter の助けが必要です! ユーザーが大人のチケットボックスに入力したものを使用したいので、グローバルとして設定しましたが、ユーザーがまだボタンをクリックしていないため、input_adult.get() はユーザーが入力した整数ではなく空白の文字列のみを返します。これを回避する方法はありますか?前もって感謝します!!
from tkinter import *
import sys
adult_fare = 7.45
child_fare = 5.00
adult_tickets = 0
def child_Gui():
mGui = Tk()
labelNo = Label(mGui, text = "How many child/concession tickets do you need?").pack()
input_child = Entry(mGui)
input_child.pack()
input_child.focus_set()
b = Button(mGui, text = "GO", width = 10, command = child_travel)
b.pack()
def adult_travel():
print(adult_tickets)
def adult_Gui():
global adult_tickets
mGui = Tk()
labelNo = Label(mGui, text = "How many adult tickets do you need?").pack()
input_adult = Entry(mGui)
input_adult.pack()
input_adult.focus_set()
b = Button(mGui, text = "GO", width = 10, command = adult_travel)
b.pack()
adult_tickets = input_adult.get()
def compare_sunday():
sunday_answer = sundayEntry.get().lower()
if sunday_answer == "yes":
global child_fare
global adult_fare
adult_fare = 3.00
child_fare = 3.00
labelNo = Label(sundayGui, text = "Ok your traveling on a sunday. All prices will be $3.00!!").pack()
okButton = Button(sundayGui, text = "Click here to continue", width = 40, command = adult_Gui).pack()
elif sunday_answer == "no":
labelNo = Label(sundayGui, text = "Ok your not traveling on a sunday.").pack()
okButton = Button(sundayGui, text = "Click here to continue", width = 40, command = adult_Gui).pack()
else:
labelElse = Label(sundayGui, text = "Please type yes or no!!").pack()
sundayGui = Tk()
sundayGui.title("Travel Calculator")
label_sunday = Label(sundayGui, text = "Are you traveling on a sunday?").pack()
sundayEntry = Entry(sundayGui)
sundayEntry.pack()
sundayEntry.focus_set()
sundayB = Button(sundayGui, text = "Go", width = 10, command = compare_sunday).pack()