簡體   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