Python:调用方法时,“ Nonetype”对象没有属性

时间:2019-02-20 14:26:25

标签: python

程序1(主程序):

class SmartPlugMain(threading.Thread):
    def __init__(self, sfile):
        #declaration
        super().__init__(daemon=True, target=self.run)
        self.gui = GUI(self)
        self.start()
        self.gui.start()

    def run(self) :
        #perform some task

if __name__=='__main__':
    sfile = '/home/file'
    SmartPlugMain(sfile)

程序2:

class GUI(threading.Thread):
    def __init__(self, smartplug02):
        super().__init__(daemon=False, target=self.run)
        self.s_plug = smartplug02
        self.main_window = None

    def run(self):
        self.main_window = SmartPlugWindow(self)
        self.main_window.run()

    def display_message(self, message):
        self.main_window.display_message(message)   <- Nonetype error message

class SmartPlugWindow(Window):
    def __init__(self, sp_main):
        super().__init__()
        # declaration

    def run(self):
       # perform task

    def display_message(self, message)
      print(message)

程序2由类组成。 当我运行程序1时,错误消息是Nonetype对象没有属性display_message。它指的是self.main_window.display_message(message)

0 个答案:

没有答案