E
E
Elen2352018-05-10 23:59:06
Python
Elen235, 2018-05-10 23:59:06

PyQT 5. Python How to assign a function to all buttons?

There are a bunch of buttons with ObjectName radioButton_1, radioButton_2...RadioButton_48...
I can't figure out how to assign a function to all buttons at once?

for i in range(1,48):
            rb = "radioButton_" + str(i)
            self.rb.setChecked(False)

It didn't work out that way.

Answer the question

In order to leave comments, you need to log in

6 answer(s)
P
planc, 2018-05-11
@planc

class MyApp:                                                                                                                                                                                                                                  
    def myFunc_1(self):                                                                                                                                                                                                                       
        print('i am myFunc_1')                                                                                                                                                                                                                
                                                                                                                                                                                                                                              
    def myFunc_2(self):                                                                                                                                                                                                                       
        print('i am myFunc_2')                                                                                                                                                                                                                
                                                                                                                                                                                                                                              
    def run(self):                                                                                                                                                                                                                            
        for i in range(1, 3):                                                                                                                                                                                                                 
            rb = 'myFunc_' + str(i)                                                                                                                                                                                                           
            getattr(self, rb)()                                                                                                                                                                                                               
                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                              
if __name__ == '__main__':                                                                                                                                                                                                                    
    MyApp().run()

L
L_I_Z, 2018-05-13
@L_I_Z

planc planc 's answer is good from a python point of view .
You need to use QGroupBox .
It groups your radiobuttons .
An example is here.
QGroupBox
QGroupBox has clicked and toggled signals to it and connect your function.

O
Oleg, 2014-06-10
@Bringoff

Nginx server, jQuery and Modernizr frameworks

Y
Yuri Lobanov, 2014-06-10
@iiil

Apparently, the site is written on the word of God.

B
BOLSHEADA, 2014-06-11
@BOLSHEADA

The next time they stop you on the street, invite them to talk about it what the site is based on)

M
Mikhail Alekseev, 2014-06-10
@Fandorin

Here is the message: "The resource at this IP address has been blocked by the decision of public authorities"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question