I try to build a code that input a certain number on lineEdit Widget and press the button Widget and I can get that value as integer type. But still the type of value I get is string. Is there any beautiful way that I can restrict type of value in lineEdit Widget as integer? Furthermore, if the type of value in lineEdit is not a integer, can Messagebox pop up showing that you input a wrong value?
import sys
from PyQt5.QtWidgets import QWidget
from PyQt5.QtWidgets import QBoxLayout
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QLineEdit, QPushButton
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt
from PyQt5 import QtGui
class Form(QWidget):
def __init__(self):
QWidget.__init__(self, flags=Qt.Widget)
self.init_widget()
def init_widget(self):
form_lbx = QBoxLayout(QBoxLayout.TopToBottom, parent=self)
self.setLayout(form_lbx)
self.le = QLineEdit()
self.btn = QPushButton("connect")
self.btn.clicked.connect(self.func1)
form_lbx.addWidget(self.le)
form_lbx.addWidget(self.btn)
def func1(self):
value = self.le.text()
if __name__ == "__main__":
app = QApplication(sys.argv)
form = Form()
form.show()
exit(app.exec_())