Hi, I have my own widgets ( simple one) and want to put them in one file and call them from second file. This is like easygui but with pyqt4.
My problem - when I call my widget from second file nothing happens.

This is file with widgets (example).

import sys
from PyQt4 import QtGui, QtCore

class QuitButtonAA(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.setGeometry(300, 300, 250, 150)
        self.setWindowTitle('Icon AA')

        quit = QtGui.QPushButton('Close', self)
        quit.setGeometry(10, 10, 60, 35)

        self.connect(quit, QtCore.SIGNAL('clicked()'),
            QtGui.qApp, QtCore.SLOT('quit()'))

class QuitButtonBB(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.setGeometry(300, 300, 250, 150)
        self.setWindowTitle('Icon BB')

        quit = QtGui.QPushButton('Close', self)
        quit.setGeometry(10, 10, 60, 35)

        self.connect(quit, QtCore.SIGNAL('clicked()'),
            QtGui.qApp, QtCore.SLOT('quit()'))

And this is second file.

import mywidgets as g

# do this
g.QuitButtonBB

# then do this
g.QuitButtonAA

Could anyone help me?

TIA

A quick look says that classes/__init__() requires parens, i.e.

g.QuitButtonBB()

If that does not solve the problem, then post back. And "(code = python)" evidently does not work. Use the plain old "(code)" instead.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

What do you expect to happen with your test code?
If you test the module properly, it will work:

# create two separate windows with a button on it
# notice that the close button will close both windows

from PyQt4 import QtGui, QtCore

class QuitButtonAA(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.setGeometry(100, 200, 250, 150)
        self.setWindowTitle('Icon AA')

        quit = QtGui.QPushButton('Close', self)
        quit.setGeometry(10, 10, 60, 35)

        self.connect(quit, QtCore.SIGNAL('clicked()'),
            QtGui.qApp, QtCore.SLOT('quit()'))

class QuitButtonBB(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.setGeometry(300, 300, 250, 150)
        self.setWindowTitle('Icon BB')

        quit = QtGui.QPushButton('Close', self)
        quit.setGeometry(10, 10, 60, 35)

        self.connect(quit, QtCore.SIGNAL('clicked()'),
            QtGui.qApp, QtCore.SLOT('quit()'))


# test the potential module
if __name__ == '__main__':
    import sys
    app =  QtGui.QApplication(sys.argv)
    b1 = QuitButtonAA()
    b1.show()
    b2 = QuitButtonBB()
    b2.show()
    app.exec_()
This question has already been answered. Start a new discussion instead.