Jan Rienyer Gadil wrote:
Sort of a newbie question:I'm affraid you have to do it manually. I think the best solution is to use a property like this:
How am i going to assign to a variable anything the user inputs on a wxTxtCtrl?
import wx
class FrameMain(wx.Frame):
def __init__(self, *args,**kwargs):
DEFAULT_VALUE = "Some string here"
wx.Frame.__init__(self, *args,**kwargs)
self.txt = wx.TextCtrl(self,value=DEFAULT_VALUE)
self._value = DEFAULT_VALUE
self._txt_updating = False
self.txt.Bind(
wx.EVT_TEXT,
self.TextChanged
)
self.value = "Test value" # This will set the property and the text control too
def TextChanged(self,event):
self._value = self.txt.GetValue()
print "Property changed to %s" % self._value
def _GetTextValue(self):
return self._value
def _SetTextValue(self,value):
if not self._txt_updating:
self._txt_updating = True
try:
self.txt.SetValue(value)
finally:
self._txt_updating = False
value = property(_GetTextValue,_SetTextValue,'Your variable')
app = wx.PySimpleApp() frame = FrameMain(None, -1, "TextValue") frame.Show(True) app.MainLoop()
In this example, the frame has a property called "value" and that has the same cached value as the text in the textcontrol.
-- http://mail.python.org/mailman/listinfo/python-list