如何在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()
答案 0 :(得分:2)
我认为你有缩进问题。试试这个:
def search_button(self):
if self.entry.get() == "example1":
print("example1")
我已经将此代码块缩进了一个额外的级别,以表明它应该是Search
方法而不是全局函数。