如何在tkinter中在画布上打印txt ['text']

我要打印

的文本
txt=canvas.create_text (...,text='this is some text') 

我希望程序打印“这是一些文字” 我使用的

print (txt['text']) 

显示错误:int object is not subscriptable

asas8520 回答:如何在tkinter中在画布上打印txt ['text']

canvas.create_text返回一个整数。这就是为什么出现错误int object is not subscriptable的原因。

您可以使用itemcget方法来获取画布上对象的属性值。第一个参数是标记,或从create_方法之一返回的ID。第二个参数是属性的名称。

在您的特定示例中,它看起来像这样:

print(canvas.itemcget(txt,"text"))
本文链接:https://www.f2er.com/2733393.html

大家都在问