【问题标题】: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()
    

    【讨论】:

      猜你喜欢
      • 2015-05-14
      • 2011-03-30
      • 1970-01-01
      • 1970-01-01
      • 2016-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-22
      相关资源
      最近更新 更多