【问题标题】:Call a class Object with Python(Tkinter)用 Python(Tkinter) 调用类对象
【发布时间】:2016-07-22 21:27:49
【问题描述】:

目前我正在寻找一种在 Tkinter 中调用类对象的方法。这是一个可以使用的示例代码。从这里我怎么能在 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()

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

【问题讨论】:

  • 旁注:我认为您的意思是root.mainloop(),而不是root.manloop()。

标签: python python-2.7 tkinter


【解决方案1】:

你调用它就像你对任何其他对象执行任何其他方法一样:你创建一个实例,然后调用该方法。

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

如果你问如何从回调中调用它,答案是一样的:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-01
    • 1970-01-01
    • 2014-07-07
    相关资源
    最近更新 更多