Python Forum

Full Version: Inherting from different class in PYQT
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to pull "self.t" from class Third and print the info in Class Fourth where it says "pass." How would I inherit it?
class Third(QWidget):
    def __init__(self, parent=None):
        super(Third, self).__init__()
        self.cp()

    def cp(self):
        for y in App.patientlist:
            if str(y[11]) == self.patnum:
                patselected = y
        self.t  = patselected
        self.bbbb.show()
    


class Fourth(QWidget):
    def __init__(self):
        super(Fourth, self).__init__()
        self.editor()
    def editor(self):
        pass ###I WANT self.t FROM CLASS THIRD PRINTED HERE.
in class forth:
local_t = Third.t
That's what I thought, but it keeps saying "Third has no attribute 't'", presumably because it's within a function and not right under Class. Of course, I can do this:
class Third(QWidget):
    t = "WHATEVER"
    def __init__(self, parent=None):
        super(Third, self).__init__()
        self.cp()
 
    def cp(self):
        for y in App.patientlist:
            if str(y[11]) == self.patnum:
                patselected = y
        t = patselected
        self.bbbb.show()
and call Third.T in another class. But it doesn't print the new value created by the function, only the one up top (in this case "WHATEVER")

Nevermind. Got it! Thank you, friend!

Nevermind. Got it! Thank you, friend!
That t wasn't there in post #1, what do you expect!