[Tutor] How to access a method defined in one class from another class (which is a thread) in Python3?

Alan Gauld alan.gauld at btinternet.com
Thu Aug 8 23:47:47 CEST 2013


On 08/08/13 22:03, SM wrote:

> [SM] Sorry that I didn't add that part. setupUI is called from the main
> as below:
>
> if __name__ == "__main__":
>      import sys
>      app = QtGui.QApplication(sys.argv)
>      MainWindow = QtGui.QMainWindow()
>      ui = Ui_MainWindow()
>      ui.setupUi(MainWindow)
>      MainWindow.show()
>      sys.exit(app.exec_())
>
> Wonder if it is necessary to call it through __init__.

Thats the problem.
You are creating a new instance inside your run() method but
the call in main() only sets it for the instance created in
main. It won't set it up for any other instance. You need
to call it every time you create a new object. Unless....

If you put it in init() it will be called every time you
create a new instance. Much safer.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list