[英]How can I ask for entry data in tkinter in python 3.4?
How can I ask for entry data in tkinter? 如何在tkinter中请求输入数据? I tried using standard if statement but it seems like I'm doing something wrong.
我尝试使用标准的if语句,但似乎我做错了什么。
from tkinter import *
class Search(Tk):
def __init__(self):
Tk.__init__(self)
self.entry = Entry(self)
self.search = Button(self, text="Search", command=self.search_button)
self.search.pack(side=LEFT)
self.entry.pack(side=LEFT)
def search_button(self):
(self.entry.get())
if Entry=="example1":
print ("example1")
app = Search()
app.mainloop()
I think you have an indentation problem. 我认为您有缩进问题。 Try this:
尝试这个:
def search_button(self):
if self.entry.get() == "example1":
print("example1")
I've indented this code block an extra level to indicate that it should be a Search
method rather than a global function. 我已将此代码块缩进一小段,以表明它应该是
Search
方法而不是全局函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.