How to read text boxes, and create action from the button in Pyqt with a form created in Designer?

Asked

Viewed 413 times

0

Good,

I designed a widget in Qt Desginer, and converted to python, and using the tutorial, I can run the widget (two textbox, 1 button and a label). The idea is to add the contents of the boxes, press the button and display the result on a label.

However, I can only run the widget, I don’t know how to read the text boxes or how to associate code at the click of the button.

The code that runs the widget is as follows:

from PyQt5 import uic
from PyQt5.QtWidgets import QApplication


Form, Window, Button = uic.loadUiType("PYQT_TUTORIAL.ui")

app = QApplication([])
window = Window()
form = Form()


form.setupUi(window)

window.show()
app.exec_()

Thanks for the help, regards.

1 answer

0

you will have to create a function to be able to call when the button is clicked ex:

# função ler a textbox e realiza a soma
def soma(self):
    valor1 = self.textbox1.Text()
    valor2 = self.textbox2.Text()
    resultado = valor1 + valor2
    self.label.setText(resultado)

# chama a função quando o botão for clicado
self.botao.clicked.connect(self.soma)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.