简体   繁体   中英

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.

how can I display a value inside the Text widget from the selected row?

I tried using textvariable attribute in Text widget but its not working.

在此处输入图像描述

Use insert method of the Text widget. 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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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