How to create labels at run time



  • Hello All,
    I have an array that gets populated based on the name of the processes at run time.For each process that is running I want to create a label and checkbox how can I do it using PyQT.I was able to do this in tkinter by using a for loop but dont know regarding Pyqt?



  • Pretty much the same way however I would create a Class that represents the object you want to create and then just instantiate additional objects as needed. Keep in mind that tkinter and pyqt5 are just different libraries to render the GUI it is still python underneath and its the python that does this kind of work.



  • @TejG

    for name in array_of_names:
        label = QLabel(name, self)
        checkbox = QCheckBox(name, self)
        # do something with these, like add them to your layout
        ...
    

    As @Denni-0 says, you might to create a "composite" QWidget which holds both the label & the checkbox, laid out as desired, rather than keeping them as separate widgets.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.