w3resource

Python PyQt basic exercises and solutions


Python PyQt basic [10 exercises with solution]


[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]

1. Write a Python program to create a blank window using PyQt.

Click me to see the sample solution

2. Write a Python program to create a basic PyQt application that opens an empty window with a specified size and title. Add various widgets (e.g. label, push button) to the blank window. Widgets should display text or perform a simple action.

Click me to see the sample solution

3. Write a Python program that creates a window with multiple widgets using vertical and horizontal layouts. Use PyQt module.

Click me to see the sample solution

4. Write a Python program that creates a PyQt application with a QLineEdit widget and a QPushButton. When the button is clicked, it should display the text entered in QLineEdit.

Note:
The QLineEdit widget is a one-line text editor.
The QPushButton widget provides a command button.

Click me to see the sample solution

5. Write a Python program using PyQt5 that creates an application with a QPushButton and a QLabel. Whenever the button is clicked, the label's text should change.

Note:
The QPushButton widget provides a command button.
The QLabel widget provides a text or image display.

Click me to see the sample solution

6. Write a Python program to create a custom widget by subclassing QWidget using PyQt. This widget should have a unique appearance or behavior.

Note:
The QWidget class is the base class of all user interface objects.

Click me to see the sample solution

7. Write a Python program using PyQt5 that asks users to change widget properties, such as color, font, or size. Observe how it affects the widget's appearance.

Click me to see the sample solution

8. Write a Python program that builds a basic calculator application with buttons for numbers and operators using PyQt. When buttons are clicked, they display the input and perform calculations.

Click me to see the sample solution

9. Write a Python program that overrides a specific event handler to customize widget behavior using PyQt.

Click me to see the sample solution

10. Write a Python program that creates a simple dialog box that displays a message or input form when a button is clicked using PyQt.

Click me to see the sample solution

Python Code Editor:


More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.

Test your Python skills with w3resource's quiz



Follow us on Facebook and Twitter for latest update.