繁体   English   中英

TKinter - 无法更新文本小部件

[英]TKinter - Unable to update Text widget

我正在尝试更新Text小部件,但无论我尝试什么都没有更新,也没有错误

def update():# a button calls this

    textBox.delete(1.0, tk.END)
    textBox.insert(tk.END,"test")


textBox = tk.Text(frame1,height=2,width=10)
textBox.config(state='disabled') #disable editing

textBox.grid(row=0,column=1,pady=2)

使用@JacksonPro 的建议

import tkinter as tk

def update():# a button calls this
    textBox.config(state="normal") # Make the state normal
    textBox.delete("0.0", "end")
    textBox.insert("end", "test")
    textBox.config(state="disabled") # Make the state disabled again


root = tk.Tk()

textBox = tk.Text(root, height=2, width=10)
textBox.config(state="disabled") #disable editing
textBox.grid(row=0, column=1, pady=2)

button = tk.Button(root, text="Click me", command=update)
button.grid(row=1, column=1)
root.mainloop()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM