Python如何在使用GUI的其他功能中使用输入文本值
问题描述:
我正在使用tkinter GUI。创建的图形用户界面,现在我的一个图形用户界面要求输入值,我需要在另一个函数中显示该输入值并打印该值。Python如何在使用GUI的其他功能中使用输入文本值
守则如下:
def EventOnBtnIO():
#some commutation
ForceNumericItem() #Called the function to open the new GUI
request = 'FF'+Value
print request
return
这是我的GUI它由输入框和按钮
def ForceNumericItem():
global Subtop
Subtop = Toplevel(top)
Subtop.geometry("350x110+500+200")
Subtop.title("Force Numeric Items")
Subtop.grab_set()
frame = Frame(Subtop,width=15, height=200,bd = 1)
frame.pack(fill = 'both',padx=3, pady=3)
# frame.config(relief=RIDGE)
global entry2
global entrytext2
entrytext2 = IntVar()
entry2 = Entry(frame,textvariable=entrytext2, width = 45)
entry2.pack(padx = 5, pady = 5)
entry2.focus_set()
entry2.selection_range(0, END)
topButtonShow = Button(frame, text = 'OK',command = ForceValue,width = 10)
topButtonBack = Button(frame, text = 'Cancel',command = okclose,width = 10)
topButtonShow.pack(side = LEFT,padx=45,pady=5)
topButtonBack.pack(side = RIGHT,padx=45,pady=5)
return
单击确定后,应采取的值,并显示在我的EventOnBtnIO功能
我认为这是关系到本地或全球varibale,但无法解决它。获取值现在
FF
期望值
FF + Value
答
在其中创建您的弹出窗口返回用户输入了一个数字之前的功能。为了解决这个问题,你可以使用.wait_window()
方法:
def EventOnBtnIO():
ForceNumericItem()
top.wait_window(Subtop)
request = 'FF'+str(Value)
print request
+1
感谢真正帮助完整.... wait_window()方法完美工作 –
[构建一个Tkinter的应用最好的办法(http://*.com/questions/17466561/best-way-to-structure-a-tkinter - 应用程序) – CommonSense
@CommonSense,明白,但没有得到我的问题的答案 –