【发布时间】:2014-01-25 23:05:30
【问题描述】:
当我尝试从代码中的输入框获取值时,它返回一个空值?我该如何解决这个问题?我已将输入框设置为字符串变量,但变量的值仍然没有?
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()
【问题讨论】:
标签: python python-2.7 tkinter