Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting QLineEdit text to float - PySide/pyQt4

How do I convert a number in a LineEdit widget to float?

Say I have:

textfield = QtGui.QLineEdit(self)

And the user inputs 12345.2 in it. I want that to be converted to a float and stored in a variable X. How do I do it?

I tried the code below, it doesn't work.

INPUT = textfield.text
INPUT2 = float(INPUT)
like image 337
HelloUni Avatar asked Dec 07 '25 06:12

HelloUni


1 Answers

text is the name of the method. You should call it to get the text inside the QLineEdit.

INPUT = textfield.text()
INPUT2 = float(INPUT)
like image 125
Avaris Avatar answered Dec 09 '25 18:12

Avaris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!