在我的代码中有 2 个按钮 - 当我单击第一个按钮时,程序写入窗口“主页”,第二个写入窗口“搜索”并在“搜索”下创建搜索栏。我的问题是,当我两次(或多次)单击“搜索”按钮时,搜索栏也会创建更多次。我该如何解决?(我总是希望只有一个搜索栏)。
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()