python - Canvas 文本更新 - Python3 Tkinter

标签 python python-3.x tkinter

我有一个带有 C.create_text 的 tkinter Canvas,由变量确定。

var = "Hello"
C = tk.Canvas(top, width = 1000, height = 500)
p = C.create_text(500, 80, text = var, font = "monaco")

当我按下按钮时,它会更改变量,但我不知道如何更新 Canvas 中的文本

def add():
    var = "Hello World"

b = tk.Button(text = "world", command = add)

最佳答案

使用

C.itemconfigure(p, text=var)

关于python - Canvas 文本更新 - Python3 Tkinter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52792254/

相关文章:

python - 接受值网格的函数

python - 创建一个字典列表,其中每个字典都包含另一个字典作为值

python - 在 Python 中实例化类的简单代码行的类型注释约定是什么?

python - 在 tkinter 中创建一个简单的应用程序来显示 map

框架内带有标签的 Python 类

python - 打开pyxl : need the max number of rows in a column that has data in Excel

python - IBM 沃森对话 : How to programmatically turn messages to counterexamples?

python-3.x - 如何结合 pytube 和 tkinter 标签来显示进度?

python - 在 tkinter 中打开文件的最简单方法

python - 从python中的字符串中删除重复的单词