[PyQt] From/Import, proper namespace,etc

JPolk jpolk5001 at yahoo.com
Sat May 19 03:07:51 BST 2012


I think I figured this out once, lol...but can't seem to recall...
Consider you have two python files,..."a" and "b"...where you "launch a" and
"import b".
But inside "b" is a PyQt call back to a control defined in "a".  I keep
getting a "not defined" error...
So,...

=======================================
File "A"
=======================================
#!/usr/bin/env python

import os
import sys
from PyQt4 import QtCore, QtGui, uic

*from b import **

class MainWindow(QtGui.QMainWindow):
        def __init__(self, parent=None):
                super(MainWindow, self).__init__(parent)

                self.setGeometry(520, 285, 640, 480)
                self.Button = QtGui.QPushButton(self)
                self.Button.setGeometry(QtCore.QRect(105, 140, 151, 66))
                self.Button.setObjectName("Button")
                self.Label = QtGui.QLabel(self)
                self.Label.setGeometry(QtCore.QRect(350, 250, 101, 21))
                self.Label.setObjectName("Label")
                self.Button.setText("Test 1")
                self.Label.setText("AAA")

                self.Button.clicked.connect(DoTest2)

def main():
        app = QtGui.QApplication(sys.argv)
        global form
        form = MainWindow()
        form.show()
        app.exec_()

if __name__ == '__main__':
        main()


=====================================
and File "B"
=====================================

#!/usr/bin/env python

def DoTest2(self):
        print("DoTest2")
        *self.Label.setText("BBB")*
        return("Done")

======================================


So,...to launch....
          prompt>>  python a.py

Then, hit the button...the button calls a function in File-B, which tries to
modify text in a Label that
is defined in File-A.....

     prompt -> python a.py
     DoTest2
     Traceback (most recent call last):
       File "b.py", line 7, in DoTest2
         self.Label.setText("BBB")
     AttributeError: 'bool' object has no attribute 'Label'

So,..what's the proper way to do this?...I've tried every which way but
nada...

Thank you,




--
View this message in context: http://python.6.n6.nabble.com/From-Import-proper-namespace-etc-tp4975143.html
Sent from the PyQt mailing list archive at Nabble.com.


More information about the PyQt mailing list