Re: How to dynamically create and populate widgets in wxglade created code.
Dietmar Schwertberger <[email protected]>
| Newsgroups | gmane.comp.python.wxglade |
|---|---|
| Message-ID | <[email protected]> |
On 11.03.2019 00:21, Dennis DeBerry via wxGlade-general wrote: > What I want to do is to create a series of radiobuttons whose lables > are the table names. Then after accessing that table create a wx.grid > where the row names are replaced by the field names and each cell next > to those row names are where the user enters the data that will be > written to that table The easiest solution would be to use a wx.Choice. A Choice control is ready to be updated with new values and actually it's more what I would expect as user. Radio buttons are a rather unusual solution. If you want to stick to it, you need to remove and add them dynamically. Anyway, you should not try to do that in the constructor of your dialog. To be able to access the sizer, you need to check the box "Store as attribute". Then you can access it as e.g. dlg.grid_sizer1 and add a sizer using e.g. dlg.grid_sizer1.Add(). Just instantiate the dialog, add/remove the radio buttons to match the required number. You can update a button's label using SetLabel. When done, show your dialog. The link you have posted, shows how to add/remove controls to/from a sizer. How to add, you can also see from the auto-generated code: grid_sizer_1.Add(self.radio_btn_1, 0, 0, 0) Also, wxGlade internally does this when you add a RadioBox (as a RadioBox can't be updated later on, wxGlade uses a static box plus RadioButtons to simulate it). See https://github.com/wxGlade/wxGlade/blob/master/widgets/radio_box/radio_box.py The methods are _set_choices and _create_button. For more information about removing, you can look at the sizer documentation. https://wxpython.org/Phoenix/docs/html/wx.Sizer.html?highlight=sizer Look at the methods Detach, Remove, Add. You could also use a Radiobox. On update you would need to remove the box from the sizer, destroy it, re-create it with the new values, add it to the sizer again. wx.grid has all kinds of methods to set rows, columns and the contents. Just have a look at the documentation or the demo. Also, please always use the simplest sizer that does the job. In your case, I would suggest to use a box sizer or a static box sizer instead of a grid sizer. Regards, Dietmar _______________________________________________ wxGlade-general mailing list wxGlade-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/wxglade-general