所以.....
我希望我的程序启动一个Tkinter GUI窗口,它为用户提供了输入值作为字符串或整数的文本框..... 下面的代码就是这样做的
from Tkinter import *
def add_text():
label1 = Label(root, text="You have entered the information to the average speed checker")
label1.pack()
root = Tk()
root.title("Average Speed Checker")
root.geometry("450x165")
veh_reg_label = Label(root, text="Vehicle Registration:")
veh_reg_label.pack()
veh_reg_text_box = Entry(root, bd=1)
veh_reg_text_box.pack()
distance_label = Label(root, text="Distance")
distance_label.pack()
distance_text_box = Entry(root, bd=1)
distance_text_box.pack()
time_label = Label(root, text="Time")
time_label.pack()
time_text_box = Entry(root, bd=1)
time_text_box.pack()
enter_button = Button(root, text="Enter", command=add_text)
enter_button.pack()
root.mainloop()
然而..... 有一个问题:我似乎无法找到一种(简单;))方式将此文本条目存储为变量,这意味着我无法继续我的程序,因为它计算汽车是否是在一段距离的道路等行驶时超过一定的速度......
答案 0 :(得分:2)
在add_text()函数中使用它:
user_entry = self.text_box_name.get()
答案 1 :(得分:-2)
这似乎有效:
def retrieve_input():
global vehicle_registration
global vehicle_time
global vehicle_distance
vehicle_registration = veh_reg_text_box.get()
vehicle_time = time_text_box.get()
vehicle_distance = distance_text_box.get()
number_checker()