While loop problem in pyqt
I am new here, so I hope it is not a wrong place to ask for pyqt.
I wrote a while loop in pyqt but I want it to stop to take input from user.I do this in python with raw_input but it doesn't work in pyqt.How can I do this in pyqt.
Code:
cev = str(ui.lineEdit.text()).lower()
guess = 0
f = 0
while cev != answer:
guess += 1
f += 1
ui.label_4.setText(answer[0:f])
if answer[0:f] == answer[0:]:
ui.label_4.setText(answer[0:f])
ui.
label_6.
setText(QtGui.
QApplication.
translate("MainWindow",
" Answer is revealed", None, QtGui.
QApplication.
UnicodeUTF8))
liste.pop(s)
return self.sor()
HERE ?
"cev = raw_input("..................:")"
I need a code here to take input from user like "raw_input"
Re: While loop problem in pyqt
Where should that input come from? Do you want to retrieve the text that user has entered into some widget?
In general it is a bad idea to have long loop in event-based application.
Re: While loop problem in pyqt
It is not a long loop.I revised the codes above.I ask a word to the user.If he makes a mistake the first letter of the answer reveals.But here because ı couldnot take another input from user the loop continues and reveals all the letters.I want it to reveal the letters one by one after the user enters his answer.
I take the input from user by line edit.
Re: While loop problem in pyqt
Quote:
Originally Posted by
neverlander
I take the input from user by line edit.
In that case you have to connect to the QLineEdit::textChanged() or some other QLineEdit signal and get rid of that loop.
Re: While loop problem in pyqt
I am not so good at pyqt.Can you give me an example on how to use it?
Re: While loop problem in pyqt
See this: http://zetcode.com/tutorials/pyqt4/widgets. It shows the typical way of doing things in Qt. In the Checkbox example you have a changeTitle() slot that is invoked every time the user clicks the check box. You don't need any loops to read data from the user -- the data will be delivered to you.
If you make a loop in your application, the event loop inside Qt won't run and Qt won't be able to redraw widgets and receive input from the user. So basically your application should only react to signals and events, instead of enforcing the program flow. Of course you can have loops in your code, but they should be short or the application will become unresponsive*.
The whole tutorial is here: http://zetcode.com/tutorials/pyqt4/
* You can use QCoreApplication::processEvents() to avoid this, but you should do that only as the last resort.
Re: While loop problem in pyqt