2014-01-25 4 views
0

입력란에서 값을 가져 오려고하면 빈 값을 반환합니까? 어떻게 해결할 수 있습니까? 입력란을 문자열 변수로 설정했지만 변수 값은 아무 것도 표시되지 않습니다..get() 입력 상자에 아무 것도 반환하지 않습니까?

import os 
import sys 
from Tkinter import * 
import tkMessageBox 

debug = Tk() #prevenets error on 'StringVar()' 
debug.withdraw() 
#global varables 
users_entry = StringVar() 

def about(): 
tkMessageBox.showinfo("About", "...") 
def convert(): 
test = users_entry.get() 
print test 
def root_window(): 
#creates main window 
root_window = Tk() 
root_window.title("convert to binary") 
root_window.geometry("600x400") 
root_window.resizable(width = FALSE, height =FALSE) 
root_window.configure(background = "gray") 
#aboutButton 
#about_button = Button(root_window, text = "about", command = about, width = 50) 
#about_button.grid(row = 0, column = 0, padx = 85, pady = 3) 
#entry box for text 
users_entry = StringVar() 
text_entry = Entry(root_window, text = "test",textvariable = users_entry, width = 70) 
text_entry.grid(row = 1, column = 0, pady = 3) 
#convert button 
convert_button = Button(root_window, text = "convert", command = convert) 
convert_button.grid() 
root_window.mainloop() 
root_window() 
debug.mainloop() 

답변

0

당신은 StringVar 오브젝트의 마스터를 설정해야합니다

users_entry = StringVar(root_window, value="ok") 
0

당신은 root_window 안에 새로운 지역 users_entry를 정의 다음 귀하의 코멘트에 users_entry는 "전역 변수"를 부르지 만.

convert에서 users_entry는 여전히 빈 문자열 스크립트의 상단에 정의 된, 하지Entry 상자에 root_window와 바인딩에 로컬로 정의 된 하나를 참조합니다.

각 방법의 맨 위에 global users_entry을 넣으십시오. 스크립트 상단에서 초기화하는 버전을 사용하십시오.

관련 문제