Answer the question
In order to leave comments, you need to log in
How to create an object (class, instance, button in gui) with a previously unknown name in Python, PyQt?
The script pulls from another file some data that is not known in advance.
and makes a dictionary out of them like:
info = {date: {finished: {id : time}}}
I would like to make a separate button in PyQt for each date (their number is not known in advance)
when clicking on which other details were shown
Please tell me how can this be done? This is how you need to dynamically set the names of the buttons. And somehow they need to be addressed after
ps and another second question, how can such data be written not in a dictionary, but in a class or instance
Answer the question
In order to leave comments, you need to log in
doper himself how to do it:
class MainWindow (QtGui.QWidget)
...
self.buttons_list ={}
for date in info:
self.buttons_list[date] = QtGui.QPushButton(self.splitter)
self.buttons_list[date].setObjectName(date)
self.buttons_list[date].setText(date)
QtCore.QObject.connect(self.buttons_list[date], QtCore.SIGNAL("clicked()"), self.tableWidget.clear)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question