Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are doing kind of circular imports which is by itself not a very good idea.</p> <p>What happens here is:<br> When you import a's <code>updateui</code> the ui variable is not imported to be.<br> The ui variable may be gloabal, but only in your a module.<br> So when you call the function <code>updatelcd</code> in <code>b</code> which calls <code>updateui</code> that was imported from <code>a</code> you get a <code>NameError</code> for <code>lcd1</code> because ui was not initialized.</p> <p>Actually I am not that sure why it does not complain about ui in the first place. It might be that python imported the knowledge that there was a global variable ui defined in a.</p> <p>Instead of just importing the function 'updateui<code>from</code>a<code>in</code>b<code>and including</code>b<code>in</code>a` you should think about how you could achieve your goal without circular imports.</p> <p>You should think about not only having modules but also classes. Make it object oriented. So what you could do:<br> 1. Create a class in your b-module which does everything the way your module does now.<br> 2. Make a constructor that takes the <code>interface.Ui_MainWindow()</code> as an argument and stores it.<br> 3. On this you will then tater be able to do your updatelcd(without going to any methods defined in a)<br> 4. Create an instance of your b-class in your a-module. On this instance you can call your function that updates the lcd.</p> <p>This is what code for your b-class could look like</p> <pre><code>class B: __init__(self, mainWindow): self.mainWindow = mainWindow def updatelcd(self): for i in range(0, 100): self.mainWindow.lcd1.setProperty("value", i) </code></pre> <p>So module a will look something like this:</p> <pre><code>import testui as interface import sys import b from PyQt4 import QtCore, QtGui ui= interface.Ui_MainWindow() thing = b.B(ui) if __name__ == "__main__": app = QtGui.QApplication(sys.argv) test = QtGui.QMainWindow() ui.setupUi(test) ui.lcd1.setProperty("value", 1) ui.button1.clicked.connect(thing.updatelcd()) test.show() app.exec_() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload