我刚刚编写了这个简单的程序,但需要 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()