python - How to make button like radiobuttons in PyQt? -


i can't seem figure out how in pyqt. makes radiobuttons, more buttons (this tkinter)
enter image description here

   radiobutton(root,                  text=txt,                 indicatoron = 0,                 width = 20,                 padx = 20,                  variable=v,                  command=showchoice,                 value=val).pack(anchor=w) 

why don't use qbuttongroup? it's exclusive default , helps keeping track , reacting on events when click on option.

code example:

from pyqt5.qtwidgets import *  app = qapplication([])  w = qwidget() w.setwindowtitle('pyqt') l = qvboxlayout(w) l.setcontentsmargins(0, 0, 0, 0) l.addwidget(qlabel('choose favorite programming language:'))  titles = ['python', 'perl', 'java', 'c++', 'c'] buttons = [qpushbutton(title) title in titles]  button_group = qbuttongroup()  button in buttons:     l.addwidget(button)     button_group.addbutton(button)     button.setcheckable(true)  w.show() app.exec() 

which looks example except differences in style (use qt stylesheets that).

enter image description here


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -