Saturday, 24 August 2013

pyside qapplication exec with while loop

pyside qapplication exec with while loop

Basically I have a program that will create a basic hello world program in
PySide qt framework. The difference is that it does print("loop") in a
while loop before exec_() is called. The problem with that the loop won't
finish until the user is done with the program, so it will only call
exec_() when the loop's done.
My problem is that if you run it like this, print("loop") will run, but
the window won't respond, and doesn't display "Hello, loop!"). If you
indent qt_app.exec_() under while running:, then the window will respond,
but print("loop") only executes once before closing the window, and
executes only once after closing it.
I need to be able to have the main window be responding while its printing
"loop" to the console multiple times.
import sys
from PySide.QtCore import *
from PySide.QtGui import *
qt_app = QApplication(sys.argv)
label = QLabel('Hello, loop!')
label.show()
running = True #only set to False when user is done with app in the real
code.
while running:
#I am handling connections here that MUST be in continual while loop
print("loop")
qt_app.exec_()

No comments:

Post a Comment