WxPython 从其他 类 导入小部件

WxPython import widgets from other classes

我是 WxPython 的初学者,我尝试过拆分代码以使其井井有条并看起来更整洁。我用简单的代码试过了,但没有用。谁能帮帮我吗?

我试过的代码:

import wx

class text_ctrl ( wx.Panel ):
    def __init ( self, parent ):
        wx.Panel.__init__ ( self, parent = parent )
        text = wx.TextCtrl ( self, pos = ( 100, 100 ) )

class Window ( wx.Frame ):
    def __init__ ( self ):
        super().__init__ ( parent = None, title = "Learn - Tab TextBox" )
        
        panel = wx.Panel()
        
        text_ctrl ( self )
        
        self.Show()

if __name__ == "__main__":
    app = wx.App()
    window = Window()
    app.MainLoop()

问题:文本框不显示(这应该是重点)。

For want of a nail the kingdom was lost

您缺少 __
如果没有 init,当您调用 text_ctrl

时什么也不会发生
import wx

class text_ctrl ( wx.Panel ):
    #def __init ( self, parent ):
    def __init__ ( self, parent ):
        wx.Panel.__init__ ( self, parent = parent )
        text = wx.TextCtrl ( self, pos = ( 100, 100 ) )

class Window ( wx.Frame ):
    def __init__ ( self ):
        super().__init__ ( parent = None, title = "Learn - Tab TextBox" )
        
       # panel = wx.Panel()
        
        text_ctrl ( self )
        
        self.Show()

if __name__ == "__main__":
    app = wx.App()
    window = Window()
    app.MainLoop()