How to access textedit fields in pyqt?
TextEdit is a widget in PyQt5 that can be used to take input from the user and display the data to the user. It can take single-line text or multiline texts. A vertical scroll bar appears if the text does not fit into the widget. Here, we will create two TextEdit fields and a button. In the first TextEdit field, we will enter a number, and then on clicking the button, 10 will be added to that number and the result will be displayed in the second TextEdit field. TextEdit widget is provided by PyQt5 that can be installed in python using the following command.
pip install PyQt5
Step 1: Let us first create the two TextEdit fields using PyQt5.
Step 2: To access the number in the first TextEdit and add 10 to it, we will use the following command.
Step 3: To put this result in the second TextEdit, we will use the following command.
Step 4: The above line of code will display the updated result in the second TextEdit.
Here, we are importing PyQt and creating a class TextEditDemo in which we are setting the size of a window and creating the two TextEdit boxes one is for taking an input and another is for showing a result after you click on a button. The result will be always adding 10 to the input number.