How can I link a set of toggle buttons like radio buttons? - python

I am using Python 3 with gobject introspection for Gtk. How can I have more than one toggle button linked together so they behave similar to tabs or radiobuttons - e.g. one is selected by default, and when another is clicked the previously active one is de-selected.
I have tried using set_sensetive, but that greys out the widget that it is applied on.

Use a Gtk.RadioButton and set draw indocator mode to False
button1 = Gtk.RadioButton("Product Codes")
button1.set_mode(False)
https://lazka.github.io/pgi-docs/Gtk-3.0/classes/ToggleButton.html#Gtk.ToggleButton.set_mode
Thx to:
https://stackoverflow.com/a/15123955/1907997
and
How can I link a set of toggle buttons like radio buttons?

Use set_active() (or props.active). Alternatively, you can create some Gtk.RadioButton widgets and set draw_indicator property to False. In the latter case you can create radio groups in normal way, without custom handling.

You listen to the toggle signals on the toggle button then call set_active() on the other ones. You need to block the toggled signals while calling set_active()so that you don't get into a loop.

Related

Display different widgets based on radio button selection

I am working on a project that is going to use tkinter. I was wondering if there was any way to display a different set of widgets based on a radio button selection and it update as soon as it is clicked
You could, for example, put your sets of widgets in different tkinter Frames and show/hide them on demand as you select different radio buttons.

Deactivate Checkbox in QT Designer

I have a (very rough) GUI created using QT Designer.
Within it there are two radio buttons. When Button A is toggled I would like the check boxes below to be unavailable for use.
When A is toggled, I would like to activate them.
Is this possible?
I have tried using the signal and slots mode, but I can only find an option to setChecked when B is toggled, not deactivate when A is toggled
It's quite simple: just connect radio button signal toggled() with group box's setVisible() slot.
This will completely hide the checkboxes.
You can also connect toggled() with every checkbox's setDisabled() slot just to deactivate them.

Buttons in vizard

I am developing a GUI in Vizard in which i am using radio buttons to select correct options, but I have a problem that I cannot solve.
In every group of radio buttons the 1st button always appears to be selected, but is actually not selected. The only way to select it is by choosing another button and then choosing the 1st button again.
Does anyone know how to solve this? I would like that in the beginning none of the buttons are selected.
I don't know Vizard but radio buttons probably have a method or another way of deselecting them similar to radiobutton.deselect() method of Tkinter. Have you looked at their documentation?
Also someone have done this trick, may be you should try it:
Create another radio button in that group, let it be selected by default and make it invisible
QuestionBox = vizinfo.add("") #Add the vizinfo object
#Create an invisible Radio button to be the default selected one, so that one of the visible ones must be chosen by the user
invisibleRadio = QuestionBox.add(viz.RADIO, 0, "")
invisibleRadio.visible(0) #invisible
source: http://forum.worldviz.com/showthread.php?t=1611

wxPython: prevent taskbar menu from closing after clicking an item

I am using wxPython to create a taskbar menu. The menu contains some menu items (obviously).
Now I would like to update/change some of these items when a particular item is clicked, while still displaying the menu.
How can I prevent the taskbar menu from disappearing after clicking an item?
The only method I've found that could be useful is wxMenu.UpdateUI(), but that doesn't prevent the menu from disappearing.
Although I never got around to trying it myself, I remember attempting a similar effect with a popup menu & textctrl. You might want to consider trying wx.lib.agw.flatmenu.FlatMenuBar, it provides an event handler OnMenuDismissed(self, event), as well as a few others, which by name appear to be what you need. You would need to create your own OnMenuDismissed() and override the event.

Custom pyGTK button

I would like to create a button that I can control the look of the button using pyGTK. How would I go about doing this?
I would like to be able to point to a new image for each 'state' the button is in (i.e. Pressed, mouse over, normal...etc.)
As described in the API documentation for gtk.Image, "If you want to receive events on the image, such as button clicks, place the image inside a gtk.EventBox, then connect to the event signals on the event box.".
You probably want to use a gtk.Image rather than a gtk.Button, since buttons require more knowledge of how the theming engine works. If you really want to use a button, you'll need to read up on gtk rc files and the APIs for manipulating them.
Here's an easy way to use an image on a button. Note that there is no text given when you initialize the button (self.button1 = gtk.Button()). Adding text there would display the text instead of the image.
self.image1 = gtk.Image()
self.image1.set_from_file('images/home.png')
self.image1.show()
self.button1 = gtk.Button()
self.button1.add(self.image1)
self.button1.show()
self.backupHBox.pack_start(self.button1, True, True)
self.button1.connect("clicked", self.quit)

Categories

Resources