【问题标题】:how to set value in Text widget in tkinter?如何在 tkinter 的文本小部件中设置值?
【发布时间】:2022-01-03 15:47:32
【问题描述】:

我的问题:当我选择一行时,我无法将值显示到 Text 小部件。

如何在文本小部件中显示所选行的值?

我尝试在 Text 小部件中使用 textvariable 属性,但它不起作用。

【问题讨论】:

  • 请发帖mvce 帮助我们帮助您!
  • 引用图片的代码是什么?
  • 现有文档涵盖了写入文本小部件。

标签: python user-interface tkinter tkinter-text


【解决方案1】:

使用Text 小部件的insert 方法。最小的例子:

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(tk.END, f"Some text\n")


tk.Button(root, text="Add text", command=add_text).pack()

root.mainloop()

【讨论】:

    猜你喜欢
    • 2020-08-25
    • 2021-11-12
    • 2014-10-26
    • 1970-01-01
    • 1970-01-01
    • 2013-04-28
    • 2013-12-06
    • 1970-01-01
    相关资源
    最近更新 更多