繁体   English   中英

如何在python 3.4中的tkinter中请求输入数据?

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

如何在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()

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

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

我已将此代码块缩进一小段,以表明它应该是Search方法而不是全局函数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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