Frage

I have trouble with editing, inputting to or even clicking a TextCtrl or actually any other widget that is not built in the init function.

Let's say I have this bit:

class firstpanel(wx.Panel):

def __init__(self, parent):
    wx.Panel.__init__(self, parent=parent)

....

def receivetext(self, event):
    panel = wx.Panel(self,size=wx.Size(850,650))
    wx.TextCtrl(self, -1, self.textfromsomewhereelse, (365, 145))

I do see the TextCtrl with the appropriate value in my GUI Frame but I can't modify it. It's exactly like I have an invisible layer over it that is not letting me through.

I say I'm missing something very basic and it's very embarresing.

War es hilfreich?

Lösung

In receivetext you create an instance of wx.TextCtrl, but you do not add it to the panel. You also do not keep a reference to the instance, so it will be destroyed immediately by the garbage collector.

class MyFrame1 (wx.Frame):
    def __init__(self):
        super(MyFrame1, self).__init__()
        fluid_sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.m_textCtrl1 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0)
        fluid_sizer.Add(self.m_textCtrl1, 0, wx.ALL, 5)
        self.SetSizer(fluid_sizer)
        self.Layout()

The example shows that a wx.BoxSizer was created and an wx.TextCtrl. The reference to the text control is stored as self.m_textCtrl. The text control is than added to the sizer, making it visible.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top