Issue
I followed PyQT Tutorial step by step.
Designing style is that UI design was made in desinger and I import UI code in python.
I'd like to ask a question about python class syntax because i can't find it when i search for it.
My qustion is that is it possible to inherit variable in python class.
import sys
from PyQt5 import uic
from PyQt5.QtWidgets import *
form_class = uic.loadUiType("C:\\PyQT tutorial\\1.Hello pyQT\\notepad.ui")[0]
class WindowClass(QMainWindow, form_class):
def __init__(self):
super().__init__()
self.setupUi(self)
In line 7, class WindowClass(QMainWindow, form_class)
I can't understand why variable form_class is there.
I think that only class name can be in parentheses.
QMainWindow is class name. however, form_class is variable.
And when i print type form_class and form_class.mro()
print(type(form_class))
print(type(form_class.mro()))
this is output
<class 'type'>
<class 'list'>
I hope you can resolve this issue as I am stuck.
Solution
All classes are objects/instances of type type
in Python. QMainWindow
is just a name that references a type
object. You can freely assign the object reference to more names such as form_class
, and it will behave identically to the name QMainWindow
.
Answered By - blhsing
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.