【问题标题】:WxPython import widgets from other classesWxPython 从其他类导入小部件
【发布时间】:2022-01-17 16:04:19
【问题描述】:

我是 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()

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

【问题讨论】:

标签: python wxpython


【解决方案1】:

因为缺少一颗钉子,王国失去了

您缺少__
如果没有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()

【讨论】:

  • 哈哈,我太傻了,谢谢!
猜你喜欢
  • 1970-01-01
  • 2023-03-24
  • 1970-01-01
  • 2020-07-16
  • 2023-03-15
  • 1970-01-01
  • 2021-10-15
  • 1970-01-01
  • 2019-04-06
相关资源
最近更新 更多