python - 新手对类(class)的困惑

标签 python class

我一直在尝试从没有类的情况下控制类中的对象,但没有成功。这些是重要的部分(不是全部!)

def GOGO():                    ################################################ 
    VFrame.SetStatusText("Ok") # ----> THIS IS WHAT I AM TRYING TO FIX        #
                               # ----> I have tried all sorts of combinations #
                               # ----> and I still can't change this property #
                               ################################################
                               # How do I fix this? What am I doing wrong???  #
                               ################################################
class VFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, -1, _("Glob"), 
                          size=(1024, 768), style=wx.DEFAULT_FRAME_STYLE)
        self.SetStatusText("Ready - Disconnected from Database.")

class MySplashScreen(wx.SplashScreen):
    def __init__(self, parent=None):
        aBitmap = wx.Image(name=img_splash).ConvertToBitmap()
        splashStyle = wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT
        splashDuration = 50
        wx.SplashScreen.__init__(self, aBitmap, splashStyle, splashDuration, parent)
        self.Bind(wx.EVT_CLOSE, self.CloseSplash)
        wx.Yield()
    def CloseSplash(self, evt):
        self.Hide()
        frame = VFrame(parent=None)
        app.SetTopWindow(frame)
        frame.Show(True)
        evt.Skip()

class MyApp(wx.App):
    def OnInit(self):
        MySplash = MySplashScreen()
        MySplash.Show()
        return True

if __name__ == '__main__':
    app = MyApp()
    app.MainLoop()

最佳答案

您需要实例化您的 VFrame 类。

frame = VFrame(parent)
frame.SetStatusText("OK")

这主要是语法糖

frame = VFrame(parent)
VFrame.SetStatusText(frame, "OK")

本质上,您必须告诉计算机您要设置哪个 VFrame 的状态文本。

关于python - 新手对类(class)的困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3868019/

相关文章:

python - 将 2D numpy 蒙版应用于灰度图像

python - 从python中的类列表中随机选择x个项目

python - 在 python 中定义和遍历树的有效方法是什么?

javascript - 正则表达式匹配/替换

c++ - 在类方法中分配给二维数组

php - PHP中如何从具有不同命名空间的扩展类调用方法

python - 删除列表中对象的重复项

css - 类的最后一个 child 不工作

python - “No URL to redirect to” 如何重定向到django同一页面

python - 查找列表的平均值