2016-07-22 129 views
-2

目前我正在寻找一种方法来调用Tkinter中的类对象。以下是可以使用的示例代码。从这我怎么可以在Tkinter中称此?用Python调用类对象(Tkinter)

root=Tk() 
root.geometry=(root, width=x, height=y) 
root.title("Let's do this!") 

class MyApp(): 
    def Do_Good(): 
     py_game=Label(root, width=x, height=y) 
    return 
root.manloop() 

问题...如何在根窗口中调用类?

+0

附注:我认为你的意思'root.mainloop()','没有根。 manloop()'。 – zondo

回答

1

您可以像对任何其他对象执行其他方法一样进行调用:创建实例并调用方法。

app = MyApp() 
... 
app.Do_Good() 

如果你问如何从一个回拨电话,这是同样的答案:

app = MyApp() 
... 
button = Button(root, text="Do good!", command=app.Do_Good)