Creating subclass for wx.TextCtrl

后端 未结 2 1385
暖寄归人
暖寄归人 2021-01-24 09:51

I\'m creating a subclass for the wx.TextCtrl in wxpython.

I want this class to add extra data to the wx.TextCtrl widgets similar as to the way extra data can be added to

2条回答
  •  感动是毒
    2021-01-24 10:12

    Instead of creating a subclass I just decided to create my own class which links an extra string value to wx.textCtrl widgets.

    Thanks to all who contributed! :)

    Heres my code:

    class TextDataHolder:
        def __init__(self, wxTextControl, data):
    
            self.wxTextControl=wxTextControl
            self.data=data
    
        def setDataTxt(self,data):
            self.wxTextControl=wxTextControl
            self.data=data
    
        def getDataTxt(self):
            return self.data
    

    Heres how I implemented it:

    import wx, TextDataHolder
    
    exampleCtrl=wx.TextCtrl(self, -1, "Hello")
    exampleData=TextDataHolder.TextDataHolder(exampleCtrl,"Sup?")
    print exampleData.getDataTxt() #prints 'Sup?'  
    

提交回复
热议问题