如何在python 3.4中询问tkinter中的入口数据?

时间:2015-03-27 19:45:12

标签: python python-3.x tkinter tkinter-entry

如何在tkinter中询问输入数据?我尝试使用标准的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()

1 个答案:

答案 0 :(得分:2)

我认为你有缩进问题。试试这个:

    def search_button(self):
        if self.entry.get() == "example1":
            print("example1")

我已经将此代码块缩进了一个额外的级别,以表明它应该是Search方法而不是全局函数。