【问题标题】:How can I pass a Text widget to a function in another module [duplicate]如何将文本小部件传递给另一个模块中的函数[重复]
【发布时间】:2021-04-22 01:02:06
【问题描述】:

是否可以将文本小部件传递给另一个文件?我有一个main.py 文件和另一个名为fuction.py 的文件。我可以执行以下操作吗?

main.py:

myText = Text(miFrame,width = 117, height = 18).place(x=20, y = 171)

function.some_function(myText)

而在function.py

def some_function(myText):
     myText.insert(END, "bla bla bla")

当我尝试执行上述代码时,我收到以下消息:

AttributeError: 'NoneType' object has no attribute 'insert' 

【问题讨论】:

标签: python tkinter


【解决方案1】:

我认为Text.place() 方法不会返回任何内容。 main.py 你可能想要的是:

myText = Text(miFrame, width=117, height=18)
myText.place(x=20, y=171)

function.some_function(myText)

【讨论】:

  • 谢谢,这是工作。
猜你喜欢
  • 2016-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-21
  • 1970-01-01
  • 2020-02-21
  • 2019-04-18
相关资源
最近更新 更多