python - Multiple windows in PyQt4? -


i've begun using pyqt4. followed tutorial (http://zetcode.com/tutorials/pyqt4/) 1 thing puzzles me part:

def main():     app = qtgui.qapplication(sys.argv)     ex = gui()     sys.exit(app.exec()) 

and reason explain here:

i have made small program opens 4 more windows except first main window. tried replicate saw worked main-window , created class every new window , tried above. looks this:

def main2():     #app = qtgui.qapplication(sys.argv)     ex2 = settings()     sys.exit(app.exec()) 

as can see have modified it. if left first line in function uncommented program crash. tried without sys.exit(app.exec_())-part make new window close milliseconds after showed. way though, runs , works. in command window, error message displays. don't know how fix this, since cannot remove last line, , dont't know replace "app" with.

i know i'm doing new windows wrong beginning, don't know how make these windows open original window in other way. haven't been able else work, , @ least runs , works right now. problem error messages in prompt, nice rid of them :)

thanks (complicated , easy ones)!

forgot mention, made classes start this:

class gui(qtgui.qmainwindow):     def __init__(self):         super(gui, self).__init__()         self.initui() 

and

class settings(qtgui.qwidget):     def __init__(self):         super(settings, self).__init__()         ...here goes more...         self.initui2() 

and open settings-window calling main2()

you must create 1 , 1 qapplication in program.

keep in mind gui programming event-driven, first declare widgets , run main loop app.exec(), when user quit application, app.exec() returns.

the qapplication purpose handle user events , propagate them code qt signals. suggest check qt documentation, it's complete, if it's targetting c++ programmers.

so instance, way create 2 widgets be:

def main():     app = qtgui.qapplication(sys.argv)      ex = qtgui.qwidget()     ex.show()     ex2 = qtgui.qwidget()     ex2.show()      sys.exit(app.exec()) 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -