1
내 코드에는 두 개의 버튼이 있습니다 - 첫 번째를 클릭하면 프로그램이 "집"창에 씁니다. 두 번째는 "검색"창과 "검색"창에 씁니다. 검색 창. 내 문제는 검색 버튼을 두 번 (또는 그 이상) 클릭하면 검색 창이 더 많이 생성된다는 것입니다. 어떻게 해결할 수 있습니까? (나는 항상 오직 하나의 검색 창을 원한다). 대신 홈 및 검색을 할 수엔트리 위젯 : 하나 이상의 검색 창을 피하십시오
class App():
def __init__(self):
self.window = Tk()
self.text=Label(self.window, text="Some text")
self.text.pack()
button_home = Button(self.window, text='Home',command= self.home)
button_home.pack()
button_search = Button(self.window, text='Search', command=self.search)
button_search.pack()
self.has_entry = False
def home(self):
self.text['text'] = 'home'
def search(self):
self.text["text"] = 'search'
if not self.has_entry:
self.meno = StringVar() # NOTE - change meno to self.meno so you can
# access it later as an attribute
m = Entry(self.window, textvariable=self.meno).pack()
self.has_entry = True
이 더욱 이동하려면 :
from tkinter import *
class App():
def __init__(self):
self.window = Tk()
self.text=Label(self.window, text="Some text")
self.text.pack()
button_home = Button(self.window, text='Home',command= self.home)
button_home.pack()
button_search = Button(self.window, text='Search', command=self.search)
button_search.pack()
def home(self):
self.text['text'] = 'home'
def search(self):
self.text["text"] = 'search'
meno = StringVar()
m = Entry(self.window, textvariable=meno).pack()
감사합니다. 많은 도움이됩니다. – user3498993