簡體   English   中英

Python tkinter 是否有在初始聲明后關閉 Text 小部件的方法?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM