[英]Python tkinter Is there a method to close the Text widget after initial declaration?
我試過 text.close() 但它給了我一個錯誤:
from tkinter import *
root = Tk()
root.config(bg='black')
def destroy_text():
text.close()
button = Button(root, label='destroy', command=destroy_text)
button.pack()
text = Text(root)
text.pack()
root.mainloop()
試試text.destroy()
。
還要將label
更改為 Button 中的text
。您會遇到錯誤。
代碼示例:
from tkinter import *
root = Tk()
def destroy_text():
text.destroy()
button = Button(root, text='destroy', command=destroy_text)
button.pack()
text = Text(root)
text.pack()
root.mainloop()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.