[英]how to set value in Text widget in tkinter?
My problem: I can't display the value to Text widget when I select a row.我的问题:当我 select 一行时,我无法将值显示到 Text 小部件。
how can I display a value inside the Text widget from the selected row?如何在选定行的Text 小部件内显示值?
I tried using textvariable attribute in Text widget but its not working.我尝试在 Text 小部件中使用textvariable属性,但它不起作用。
Use insert
method of the Text
widget.使用Text
小部件的insert
方法。 Minimal example:最小的例子:
import tkinter as tk
root = tk.Tk()
text = tk.Text(root)
text.pack()
def add_text():
# text.delete(1.0, tk.END) # Uncomment if you need to replace text instead of adding
text.insert(1.0, f"Some text\n")
tk.Button(root, text="Add text", command=add_text).pack()
root.mainloop()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.