473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

wxPython: updating style of StaticText from event generated by button

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
4 6558
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: plumpy321 | last post by:
Hi, I took an example from wxPython with the IE web browser and created a refresh button to automatically refresh a web page in 5 second intervals. But I notice that the memory utilization in...
0
by: flupke | last post by:
Hi, i need to develop a gui which will load several "windows" depending on what the users selects in the menu and i thought i could accomplish this with panels. What i'm trying to do to test...
1
by: PeterG | last post by:
Hi, I am relatively new to Python, and am learning it as part of a university module... Im currently undertaking a project to create an IM server and IM gui client. I have a very basic...
3
by: John Salerno | last post by:
I'm using the sample code of the file 'simple.py' and trying to make a single window with a panel in it, but I keep getting an error. Here's my code: (I know I might need something else, like a...
2
by: John Salerno | last post by:
Ah, the object-oriented stuff is just so FUN! :) Here's my code, followed by the error. I thought I was referring to the 'text' attribute correctly, but it seems not. import wx class...
9
by: zxo102 | last post by:
Hi everyone, I am using a python socket server to collect data from a socket client and then control a image location ( wxpython) with the data, i.e. moving the image around in the wxpython frame....
1
by: kath | last post by:
Hello, sorry about the lengthy message. I finding difficult to execute this program. The wx.Notebook i created is coming on the splitted frame(self.p2). How do I that. I am started to learn...
9
by: Tyler | last post by:
Hello All: I am currently working on a project to create an FEM model for school. I was thinking about using wxPython to gather the 12 input variables from the user, then, after pressing the...
3
by: Gandalf | last post by:
I try to reach a specific wx StaticText element's text and to change it by clicking on a button now let's say the this is my element: wx.StaticText(panel, 15, "Hello" ,(30, 70) ,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.