dimanche 16 octobre 2022

Create Check box's with different object name in Python

I am using XML file that has a set of elements inside. I want to create a check box for each element with different object name so the user can select only one of them and apply specific function for the selected one. so far I was able to loop inside the xml and create the check box's but all with the same object name but this is not good for me since each functionality is link to all selected.

my code looks like this:

import xml.etree.ElementTree as et
tree = et.parse('C:\Python_Projects\Jira_Rest\myviews.xml')
        num_reporters = tree.findall('.//view')

y=160
        p = 0
        for i in range(0, len(num_reporters)):
            view = (my_views[i].attributes['viewname'].value)

            self.checkbox = QtWidgets.QCheckBox(self.centralwidget)
            self.checkbox.setGeometry(QtCore.QRect(160, y, 211, 17))
            font = QtGui.QFont()
            font.setFamily("MS Shell Dlg 2")
            font.setPointSize(9)
            font.setBold(False)
            font.setItalic(False)
            font.setWeight(9)
            self.checkbox.setFont(font)
            self.checkbox.setStyleSheet("font: 75 9pt \"MS Shell Dlg 2\";")
            self.checkbox.setObjectName("checkBox" + str(p))
            self.v.setText(view)
            y+=40
            p=p+1



Aucun commentaire:

Enregistrer un commentaire