Hi! I wish to have a default value on the text area of combobox to
help users to understand what to do. For help you to understand what I
mean take a look at this example: http://dl.dropbox.com/u/8044435/login.jpg
There isn't anything built-in for that, but it's not hard to implement. Just use SetValue to set your message when the widget is created. You'll also want to compare the value with that message when you later get the value from the widget, and if it is the same as the message then treat it as if it was empty. For extra niceness you can watch for when the user clears any value that they've started typing and then reset the widget's value to the starting message again, and it's also nice to change the foreground colour to a medium grey when the message is displayed.
···
On 5/6/11 1:33 AM, artwood wrote:
Hi! I wish to have a default value on the text area of combobox to
help users to understand what to do. For help you to understand what I
mean take a look at this example: http://dl.dropbox.com/u/8044435/login.jpg
--
Robin Dunn
Software Craftsman
This may be helpful;
class MyTextCtrl(wx.TextCtrl):
def init(self, parent, ID = -1, value = wx.EmptyString, pos = wx.DefaultPosition,
size = wx.DefaultSize, style = 0, validator = wx.DefaultValidator):
super(MyTextCtrl, self).init(parent, ID, value = value, pos = pos, size = size, style = style,
validator = validator)
self.empty_value = value
self.default_foreground_color = self.GetForegroundColour()
self.Bind(wx.EVT_SET_FOCUS, self.on_focus)
self.Bind(wx.EVT_KILL_FOCUS, self.on_leave)
self.SetForegroundColour(wx.Color(84, 84, 84))
def GetValue(self):
val = super(MyTextCtrl, self).GetValue()
return “” if val == self.empty_value else val
def GetValue_(self):
return super(MyTextCtrl, self).GetValue()
def on_focus(self, evt):
if self.empty_value == self.GetValue_():
self.SetForegroundColour(self.default_foreground_color)
self.ChangeValue(“”)
def on_leave(self, evt):
if self.empty_value == self.GetValue_() or self.GetValue_() == “”:
self.SetForegroundColour(wx.Color(84, 84, 84))
self.ChangeValue(self.empty_value)
For example:
txt_box = MyTextCtrl(self, -1, value = “Username”)
Ozan HACIBEKIROGLU
···
On Fri, May 6, 2011 at 11:33 AM, artwood zooropa86@gmail.com wrote:
Hi! I wish to have a default value on the text area of combobox to
help users to understand what to do. For help you to understand what I
mean take a look at this example: http://dl.dropbox.com/u/8044435/login.jpg
–
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en