2014-06-29 71 views
0

我有一个文本框创建,但我怎么会得到一个函数的输入。阅读文本框的内容

userbox = Text(root, width = 10, height = 1, wrap = WORD) 
userbox.pack() 

passwordbox = Text(root, width = 10, height = 1, wrap = WORD) 
passwordbox.pack() 

b2 = Button(root,text="Submit Login") 
b2.pack() 
b2.configure(command=login) 

我如何得到这个被处理。 I.E.如果用户名=“名”和密码=“密码” print "welcome"如果不是print"incorrect login"

+0

你真的应该使用['Entry'部件(http://effbot.org/tkinterbook/entry.htm)。 –

回答

2

由于@BurhanKhalid指出,你应该使用Tk.Entry()插件这样的事情。假设您使用的是Tk.Entry小部件,则可以使用get()属性获取小部件的文本。

代码:

def login(): 
    if userbox.get() == "name" and passwordbox.get() == "password": 
     print "welcome" 
    else: 
     print"incorrect login" 

userbox = Entry(root, width = 10) 
userbox.pack() 

passwordbox = Entry(root, width = 10) 
passwordbox.pack() 

b2 = Button(root,text="Submit Login") 
b2.pack() 
b2.configure(command=login)