Python Forum
Inherting from different class in PYQT
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Inherting from different class in PYQT
#1
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.
Reply
#2
in class forth:
local_t = Third.t
Reply
#3
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!
Reply
#4
That t wasn't there in post #1, what do you expect!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020