I am trying to make a data structure using NamedTuple (I could switch to dataclass if it's preferable!) to contain a PyQt5 QWidget. I need to set the type of the widget but also would like to set a default.
When I check type(PyQt5.QtGui.QLabel())
it returns <class 'PyQt5.QtWidgets.QLabel'>
Trying
from typing import NamedTuple
import PyQt5
class myStat(NamedTuple):
name:str
value:float=0.0
qlabel:PyQt5.QWidgets.QLabel=PyQt5.QtGui.QLabel()
I cannot import it to my actual application with from myFile import myStat
I get the error `QWidget: Must construct a QApplication before a QWidget.
Any advice on how to do this? Inside my application I'm trying to do
x=myStat(name='foo',value=5.0)
but it's evidently not even getting there since it's failing on import.
question from:https://stackoverflow.com/questions/65623132/namedtuple-or-dataclass-containing-default-pyqt5-qwidget