python文本框_Python GUI-在文本框中插入文本

我刚刚进入了pythongui,我正在测试不同的东西,因为这似乎可以帮助我更容易地学习(尝试和错误)。我正在尝试的一件事是插入另一个类的消息。我可以说,我不知道我会用这个做什么,但我只是为了尝试。# Hello World

# Displays "Hello World!" in a text box.

from tkinter import *

class myClass(object):

def myMethod():

print("Hello World!")

class Application(Frame):

""" GUI application which can reveal the secret of longevity. """

def __init__ (self, master):

super(Application, self).__init__(master)

self.grid()

self.createWidgets()

def createWidgets(self):

# Create a text box

self.txtBox = Text(self, width = 300, height = 300, wrap = WORD)

self.txtBox.grid(row = 0, column = 0, sticky = W)

# display message

message = myClass.myMethod

self.txtBox.insert(0.0, message)

# main

root = Tk()

root.title("My Title")

root.geometry("500x500")

app = Application(root)

root.mainloop()

当我运行.py文件时,我会得到一个GUI,然后是一个写着的框——如果我没有弄错,这意味着这就是我的方法存储在内存中的地方。

所以我用message = myClass.myMethod()来思考,这将输出“Hello World!”-相反,我得到一个错误。一开始它是沿着对象的线的。init不接受参数或类似的东西(抱歉,因为我无法重新创建错误)-现在我得到了tkinter.TclError: wrong # args: should be "43128536.43105360 insert index chars ?tagList chars tagList...?

这有可能有“你好的世界!”从另一个类,在GUI文本框中打印?

而且,当我在查看代码时,我很好奇。app = Application(root)的目的是什么?当我没有它的时候,我会得到一个空白的图形用户界面。但是,我看不出它实际上调用app做任何事情,只是将其设置为Application(root)。