Hi Rene,
your example use the panel id to find the button.
My problem is different I have one wx.Frame (no panel) with a lot of buttons and when one button is
pressed I know witch was by the index, but I need to change the color of the button and
don’t know how to reference it.
Hi Rene,
your example use the panel id to find the button.
My problem is different I have one wx.Frame (no panel) with a lot of buttons
and when one button is
pressed I know witch was by the index, but I need to change the color of the
button and
don't know how to reference it.
Just put a line like this:
button = event.GetEventObject()
in your OnSetRank method and you'll get the reference to the button.
Hi Rene,
your example use the panel id to find the button.
My problem is different I have one wx.Frame (no panel) with a lot of buttons and when one button is
pressed I know witch was by the index, but I need to change the color of the button and
don’t know how to reference it.
Attached goes a files with my code.
Thank for your help.
There are a number of ways to do this here a couple,
Well one problem is solved!
But I need to change the labels for example just in some
buttons due to update, without any event!
How do I update a button without a event?
Hi Rene,
your example use the panel id to find the button.
My problem is different I have one wx.Frame (no panel) with a lot of buttons and when one button is
pressed I know witch was by the index, but I need to change the color of the button and
don’t know how to reference it.
Attached goes a files with my code.
Thank for your help.
There are a number of ways to do this here a couple,
Andrea and Cody already gave you answers. I can’t tell more or better (I’m a newbie in programming, Python and wxPython).
Just one remark: I don’t understand why you say “no panel”. Actually you do create one in your init function and you pass the panel as an argument of the mk_btn function, which in turn calls the buildOneButton function where the parent is the panel. My understanding of a panel is that it serves as “a container to contain controls”. It seems to be a good idea to always have a panel to put buttons on it. I tried once and it behaves differently. For instance, when you create a button with a frame (wx.Frame) as a parent, the button occupies immediately the whole frame surface.
Hi Rene,
your example use the panel id to find the button.
My problem is different I have one wx.Frame (no panel) with a lot of buttons and when one button is
pressed I know witch was by the index, but I need to change the color of the button and
don’t know how to reference it.
Buttons, like any widget, do have an id (either by default when id=-1 or one set with id=wx.NewID() or by explicit assignment id=123) but I understand they also have a name (a feature I have never tried). When you create the button, you could try giving the button the same name as its label (in your case str(cnt)) and later use the name to identify the specific button you wish.
I hope what I say makes sense. If not you must wait for a suggestion from experts.
Hi Rene,
your example use the panel id to find the button.
My problem is different I have one wx.Frame (no panel) with a lot of buttons and when one button is
pressed I know witch was by the index, but I need to change the color of the button and
don’t know how to reference it.
Attached goes a files with my code.
Thank for your help.
There are a number of ways to do this here a couple,
Hello Jorge,
Andrea and Cody already gave you answers. I can't tell more or better (I'm a newbie in programming, Python and wxPython).
Just one remark: I don't understand why you say "no panel". Actually you do create one in your __init__ function and you pass the panel as an argument of the mk_btn function, which in turn calls the buildOneButton function where the parent is the panel. My understanding of a panel is that it serves as "a container to contain controls". It seems to be a good idea to always have a panel to put buttons on it. I tried once and it behaves differently. For instance, when you create a button with a frame (wx.Frame) as a parent, the button occupies immediately the whole frame surface.
Good work,
Rene
I think there's some old examples out there that still use the frame as a parent rather than a panel. The frame will not look native on Windows though, so it is recommended practice to use a panel for the widget container as the panel object looks right on all platforms.
If Jorge set the size of the buttons or just has multiple ones, then they shouldn't take up all the space.
Well one problem is solved!
But I need to change the labels for example just in some
buttons due to update, without any event!
How do I update a button without a event?
Thank you.
I must be missing something here. How do you know when a button needs its label changed if there is no event to let the GUI know that? Or are you polling for data and you want the buttons labels to change depending on what data is being returned? Either way, it's pretty easy:
Of course, you may want to enclose the SetLabel calls in an "if" statement since it sounds like you want to conditionally change the button labels based on some nebulous concept that you haven't explained.
Hello Jorge,
Andrea and Cody already gave you answers. I can’t tell more or better (I’m a newbie in programming, Python and wxPython).
Just one remark: I don’t understand why you say “no panel”. Actually you do create one in your init function and you pass the panel as an argument of the mk_btn function, which in turn calls the buildOneButton function where the parent is the panel. My understanding of a panel is that it serves as “a container to contain controls”. It seems to be a good idea to always have a panel to put buttons on it. I tried once and it behaves differently. For instance, when you create a button with a frame (wx.Frame) as a parent, the button occupies immediately the whole frame surface.
Good work,
Rene
I think there’s some old examples out there that still use the frame as a parent rather than a panel. The frame will not look native on Windows though, so it is recommended practice to use a panel for the widget container as the panel object looks right on all platforms.
If Jorge set the size of the buttons or just has multiple ones, then they shouldn’t take up all the space.
Buttons, like any widget, do have an id (either by default when id=-1 or one set with id=wx.NewID() or by explicit assignment id=123) but I understand they also have a name (a feature I have never tried). When you create the button, you could try giving the button the same name as its label (in your case str(cnt)) and later use the name to identify the specific button you wish.
I hope what I say makes sense. If not you must wait for a suggestion from experts.
Hi Rene,
your example use the panel id to find the button.
My problem is different I have one wx.Frame (no panel) with a lot of buttons and when one button is
pressed I know witch was by the index, but I need to change the color of the button and
don’t know how to reference it.
Attached goes a files with my code.
Thank for your help.
There are a number of ways to do this here a couple,
Buttons, like any widget, do have an id (either by default when id=-1 or one set with id=wx.NewID() or by explicit assignment id=123) but I understand they also have a name (a feature I have never tried). When you create the button, you could try giving the button the same name as its label (in your case str(cnt)) and later use the name to identify the specific button you wish.
I hope what I say makes sense. If not you must wait for a suggestion from experts.
Hi Rene,
your example use the panel id to find the button.
My problem is different I have one wx.Frame (no panel) with a lot of buttons and when one button is
pressed I know witch was by the index, but I need to change the color of the button and
don’t know how to reference it.
Attached goes a files with my code.
Thank for your help.
There are a number of ways to do this here a couple,
Hi Mike,
you are right about the panel, but it’s from another test I’m doing.
I partial solve my main problem:
to update the label buttons r according to what is in a database.
How?
When the buttons are created I make a copy of the object to a list then I recall the list
and update the button.
Your method, Mike is easy but I have 400 buttons to process!
But I need to change the labels for example just in some
buttons due to update, without any event!
How do I update a button without a event?
Thank you.
I must be missing something here. How do you know when a button needs its label changed if there is no event to let the GUI know that? Or are you polling for data and you want the buttons labels to change depending on what data is being returned? Either way, it’s pretty easy:
Of course, you may want to enclose the SetLabel calls in an “if” statement since it sounds like you want to conditionally change the button labels based on some nebulous concept that you haven’t explained.
Buttons, like any widget, do have an id (either by default when id=-1 or one set with id=wx.NewID() or by explicit assignment id=123) but I understand they also have a name (a feature I have never tried). When you create the button, you could try giving the button the same name as its label (in your case str(cnt)) and later use the name to identify the specific button you wish.
I hope what I say makes sense. If not you must wait for a suggestion from experts.
Hi Rene,
your example use the panel id to find the button.
My problem is different I have one wx.Frame (no panel) with a lot of buttons and when one button is
pressed I know witch was by the index, but I need to change the color of the button and
don’t know how to reference it.
Attached goes a files with my code.
Thank for your help.
There are a number of ways to do this here a couple,
Hi Mike,
you are right about the panel, but it's from another test I'm doing.
I partial solve my main problem:
to update the label buttons r according to what is in a database.
How?
When the buttons are created I make a copy of the object to a list then I recall the list
and update the button.
Your method, Mike is easy but I have 400 buttons to process!
Give yourself what I call an "access path". In other words create some way to keep track of the buttons when you create them and then use that thing to access them later. What that access path will be can depend on your situation. For example, if they all have a unique name (or you can give them one) and you are able to know or calculate that name later when you want to change the label, then something based on the name is called for. (Two examples of that are a simple Python dictionary, or using the widget name attribute and thePanel.FindWindowByName(name))
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
Hi Mike,
you are right about the panel, but it's from another test I'm doing.
I partial solve my main problem:
to update the label buttons r according to what is in a database.
How?
When the buttons are created I make a copy of the object to a list then I recall the list
and update the button.
Your method, Mike is easy but I have 400 buttons to process!
Thank you.
Maybe you're already doing this, but if you keep a list of your buttons, you can do something like this:
myBtnLst = [self.btnOne, self.btnTwo, self.btnThree]
for button in myBtnLst:
button.SetLabel("new label")
Or you can do it generically using some code like this:
children = panel.GetChildren()
for child in children:
if isinstance(child, wx.Button):
child.SetLabel("new label")
Of course, you'll also need to keep track of where you are in your list of data as well, probably by using a counter of some sort.
Thanks a lot Robin and Mike,
I thing I did what you suggest: keep track of the buttons in a list, and it works fine,
now I have another problem and made another post to the list.