wxPython: updating style of StaticText from event generated by button
Andrea Gavana
andrea_gavana at tin.it
Wed Nov 2 18:20:42 EST 2005
Hello Kees,
> and via the even handler I try to give StaticText a different style:
In general you *can not* change in runtime the style of a widget. Only a
very limited subset of the wxPython widgets supports style changes in
runtime. I would suggest you 2 alternatives:
1) Use wx.lib.stattext ==> GenStaticText (but I am not sure it will work, I
don't think so, but you can try it);
2) Every time you call your event binder, Destroy() the StaticText with the
old style and create a new one with the style you need. For example
(untested code!!!):
def VeranderLabel(self, event):
if self.text1.GetWindowStyle() == wx.SUNKEN_BORDER:
MyStyle = wx.RAISED_BORDER
else:
MyStyle = wx.SUNKEN_BORDER
self.text1.Destroy()
self.text1 = wx.StaticText(self.panel, -1, "Dikke Henk en gekke Greetje",
size=(100,50), pos=(15,20),
style=MyStyle)
self.Refresh()
HTH.
Andrea.
--
"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77
"KvS" <keesvanschaik at gmail.com> ha scritto nel messaggio
news:1130886746.328723.109570 at f14g2000cwb.googlegroups.com...
> Hi all,
>
> I'm pretty new to (wx)Python so plz. don't shoot me if I've missed
> something obvious ;). I have a panel inside a frame, on which a Button
> and a StaticText is placed:
>
> self.panel = wx.Panel(self,-1)
> self.button = wx.Button(self.panel,-1,"Klikkerdeklik")
> self.button.SetPosition((200,40))
> self.Bind(wx.EVT_BUTTON, self.VeranderLabel, self.button)
> self.text1 = wx.StaticText(self.panel, -1, "Dikke Henk en gekke
> Greetje", size=(100,50), pos=(15,20), style=wx.RAISED_BORDER)
>
> and via the even handler I try to give StaticText a different style:
>
> def VeranderLabel(self, event):
> if self.text1.GetWindowStyle() == wx.SUNKEN_BORDER:
> self.text1.SetWindowStyle(wx.RAISED_BORDER)
> self.text1.Refresh()
> self.text1.Update()
> else:
> self.text1.SetWindowStyle(wx.SUNKEN_BORDER)
> self.text1.Refresh()
> self.text1.Update()
>
> Although the style is indeed updated (checked by printing style to
> console) the appearance of the StaticText stays the same. What am I
> missing here?
>
> Thanks in advance.
>
> - Kees
>
More information about the Python-list
mailing list