python - How to make button like radiobuttons in PyQt? -
i can't seem figure out how in pyqt. makes radiobuttons, more buttons (this tkinter)
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).
Comments
Post a Comment