Reputation: 994
How can I ask for entry data in tkinter? I tried using standard if statement but it seems like I'm doing something wrong.
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()
Upvotes: 0
Views: 604
Reputation: 49318
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.
Upvotes: 2