2015-10-21 26 views
0

好了,這裏是我的問題:正常打印錄入組件輸入Python3.5

下面的代碼,當由按鈕呼籲,版畫NOTHING。爲什麼? (是的,我當然在打字輸入到輸入框)

options = Tk() 
options.geometry("218x156") 
options.iconbitmap('original.ico') 
options.title("Options") 

Label(options, text = "GitHub Username:").pack() 
userName = StringVar() 
Entry(options, width = "30", textvariable = userName).pack() 

Label(options, text = "GitHub Email:").pack() 
userEmail = StringVar() 
Entry(options, width = "30", textvariable = userEmail).pack() 

Label(options, text = "GitHub Password:").pack() 
userPassword = StringVar() 
Entry(options, show = "•", width = "30", textvariable = userPassword).pack() 

def optionSave(): 
    print(userName.get()) 
    print(userEmail.get()) 
    print(userPassword.get()) 
    options.destroy() 

作品,

def fileOptions(): 
    options = Tk() 
    options.geometry("218x156") 
    options.iconbitmap('original.ico') 
    options.title("Options") 

    Label(options, text = "GitHub Username:").pack() 
    userName = StringVar() 
    Entry(options, width = "30", textvariable = userName).pack() 

    Label(options, text = "GitHub Email:").pack() 
    userEmail = StringVar() 
    Entry(options, width = "30", textvariable = userEmail).pack() 

    Label(options, text = "GitHub Password:").pack() 
    userPassword = StringVar() 
    Entry(options, show = "•", width = "30", textvariable = userPassword).pack() 

    def optionSave(): 
     print(userName.get()) 
     print(userEmail.get()) 
     print(userPassword.get()) 
     options.destroy() 

請注意:的唯一明顯的區別是

t他的底部沒有包住它def fileOptions():

輸出爲空白。如在其中打印zilch到控制檯。這是因爲它在一個單獨的窗口?如果是這樣,我該如何解決它?

回答

0

現在...回答我自己的問題!

相反的:

userName = StringVar() 
Entry(options, width = "30", textvariable = userName).pack() 

定義輸入構件,像這樣:

userName = StringVar() 
userName = Entry(options, width = "30") 
userName.pack() 

移動.pack()到它自己的行userName.pack() ,然後打印出來,像這樣:

print(userName.get()) 

對於您想要的所有Entry小部件。