Jak mogę poprosić o dane wejściowe w tkinter? Próbowałem użyć standardowej instrukcji if, ale wygląda na to, że robię coś źle.
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()
Odpowiedzi:
2 dla odpowiedzi № 1Myślę, że masz problem z wcięciem. Spróbuj tego:
def search_button(self):
if self.entry.get() == "example1":
print("example1")
Zrobiłem wcięcie tego bloku kodu na dodatkowy poziom wskazujący, że powinien to być Search
metoda, a nie funkcja globalna.