简体   繁体   中英

How can I ask for entry data in tkinter in python 3.4?

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()

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM