By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,301 Members | 1,741 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,301 IT Pros & Developers. It's quick & easy.

wxPython: updating style of StaticText from event generated by button

P: n/a
KvS
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

Nov 1 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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" <ke***********@gmail.com> ha scritto nel messaggio
news:11**********************@f14g2000cwb.googlegr oups.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

Nov 1 '05 #2

P: n/a
KvS
Thanks :), I'll give both of your hints a try. What I basically want to
do is have something like an "old style" button in win xp that's either
"up" or "down", since I couldn't find a more straightforward method I
thought taking a text widget and adjusting the border at mouse click
would be the best alternative no?

One question then, what's the use of having a method like
SetWindowStyle() if it doesn't really do anything at runtime? Is it
indeed just intended for the few widgets that do support it?

- Kees

Nov 1 '05 #3

P: n/a
Hello Kees,
Thanks :), I'll give both of your hints a try. What I basically want to
do is have something like an "old style" button in win xp that's either
"up" or "down", since I couldn't find a more straightforward method I
thought taking a text widget and adjusting the border at mouse click
would be the best alternative no?
I would suggest you to take a look to the wxPython "custom" buttons; you can
find them in the demo, under "Custom Controls" ==> "GenericButtons". There
you will find "old style" buttons, that can be simple buttons or toggle
buttons (with "up" and "down" states). I have XP, and they look like "old
style" buttons. Moreover (just to promote my web site and my widgets, freely
available to all wxPython users ;-)))) ), if you would like to use
"non-rectangular" buttons-toggle buttons, you could take a look at:

http://xoomer.virgilio.it/infinity77...l#shapedbutton
One question then, what's the use of having a method like
SetWindowStyle() if it doesn't really do anything at runtime? Is it
indeed just intended for the few widgets that do support it?


This is more a wxWidgets question that a wxPython one. However, quoting the
wxWidgets manual:

wxWindow::SetWindowStyleFlag
virtual void SetWindowStyleFlag(long style)

Sets the style of the window. Please note that some styles cannot be changed
after the window creation and that Refresh() might be called after changing
the others for the change to take place immediately.

SetWindowStyleFlag is the same as SetWindowStyle. I don't have an answer to
your question, but maybe some wxWidgets expert can give you some more hints
(I don't use wxWidgets, only wxPython).

HTH.

Andrea.
"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77
Nov 2 '05 #4

P: n/a
KvS
I would suggest you to take a look to the wxPython "custom" buttons; you can
find them in the demo, under "Custom Controls" ==> "GenericButtons". There
you will find "old style" buttons, that can be simple buttons or toggle
buttons (with "up" and "down" states). I have XP, and they look like "old
style" buttons.
Pff. Sorry, apparently I just completely missed that specific part of
the demo although I've been using the demo all the time so far. :(.
This is more a wxWidgets question that a wxPython one. However, quoting the
wxWidgets manual:


Yes, I had looked it up in the manual, but "Please note that some
styles cannot be changed after the window creation [...]" is hardly the
same as "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" right ;).

Thanks for the great help!

- Kees

Nov 2 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.