【问题标题】:Python tkinter Is there a method to close the Text widget after initial declaration?Python tkinter 是否有在初始声明后关闭 Text 小部件的方法?
【发布时间】:2020-01-19 09:14:56
【问题描述】:
我试过 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()
【问题讨论】:
标签:
python
tkinter
text
widget
【解决方案1】:
试试text.destroy()。
还要在您的 Button 中将 label 更改为 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()