TLS_R
TLS_R

Reputation: 17

WxPython import widgets from other classes

I'm a beginner in WxPython and I've tried experimenting splitting up the code to make it organized and look neater. I've tried it with simple code but it doesn't work. Can anyone please give me a hand?

The code I've tried:

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

Problem: Textbox doesn't show up ( which is supposed to be the main point ).

Upvotes: 1

Views: 82

Answers (1)

Rolf of Saxony
Rolf of Saxony

Reputation: 22443

For want of a nail the kingdom was lost

You are missing a __
Without the init, nothing occurs when you call 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()

enter image description here

Upvotes: 1

Related Questions