2017-04-12 42 views
0

我正在使用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 
+1

[構建一個Tkinter的應用最好的辦法(http://stackoverflow.com/questions/17466561/best-way-to-structure-a-tkinter - 應用程序) – CommonSense

+0

@CommonSense,明白,但沒有得到我的問題的答案 –

回答

1

在其中創建您的彈出窗口返回用戶輸入了一個數字之前的功能。爲了解決這個問題,你可以使用.wait_window()方法:

def EventOnBtnIO(): 
    ForceNumericItem() 
    top.wait_window(Subtop) 
    request = 'FF'+str(Value) 
    print request 
+1

感謝真正幫助完整.... wait_window()方法完美工作 –

相關問題