Python GUI – How to Make Expression Evaluator in PyQt5

In this Python GUI article iam going to show you How to Make Expression Evaluator in

PyQt5, so before starting our main topic if your interested in Python GUI Development with

PyQt5, you can check the below link.

 

 

 

Also you can check more Python GUI articles in the below links

1: Kivy GUI Development Tutorials

2: Python TKinter GUI Development 

3: Psyide2 GUI Development 

4: wxPython GUI Development 

5: PyQt5 GUI Development Course

 

 

 

 

So now this is the complete code for Python GUI – How to Make Expression Evaluator in PyQt5

 

 

 

 

 

OK at the top first we have imported our required classes from PyQt5 library.

 

 

 

 

Also this is our main window class that inherits from QWidget, and we have some requirements

of the window like title, width, height of the window, also we have called our UI() method

in this class.

 

 

 

 

 

This is our UI() method that we have created the object of QTextBrowser with QLineEdit,

also we have created a QVBoxLayout, and at the end we have connected the reurnPressed

signal of QLineEdit with updateBrowser() method.

 

 

 

 

 

What is QTextBrowser Class ?

This class extends QTextEdit (in read-only mode), adding some navigation functionality

so that users can follow links in hypertext documents.

If you want to provide your users with an editable rich text editor, use QTextEdit. If you want

a text browser without hypertext navigation use QTextEdit, and use QTextEdit::setReadOnly()

to disable editing. If you just need to display a small piece of rich text use QLabel.

 

 

 

 

Document Source and Contents

The contents of QTextEdit are set with setHtml() or setPlainText(), but QTextBrowser also implements the setSource() function, making it possible to use a named document as the source text. The name is looked up in a list of search paths and in the directory of the current document factory.

If a document name ends with an anchor (for example, “#anchor”), the text browser automatically scrolls to that position (using scrollToAnchor()). When the user clicks on a hyperlink, the browser will call setSource() itself with the link’s href value as argument. You can track the current source by connecting to the sourceChanged() signal.

 

 

 

 

Also this is our method or slot that we have connected with returnPressed signal of QLineEdit.

 

 

 

 

 

So in here every PyQt5 application must create an application object. The sys.argv

 parameter is a list of arguments from a command line.

 

 

 

 

Finally, we enter the mainloop of the application. The event handling starts from this point. 

 

 

 

 

OK now run the complete code and this will be the result

Python GUI - How to Make Expression Evaluator in PyQt5
Python GUI – How to Make Expression Evaluator in PyQt5

 

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Share via
Copy link
Powered by Social Snap
×