w3resource

Python PyQt connecting signals to slots - Exercises and solutions

Python PyQt Connecting Signals to Slots [15 exercises with solution]

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

These exercises cover a range of scenarios related to signals and slots in PyQt. They allow users to practice connecting signals to slots, emitting custom signals, handling various user interactions, and utilizing built-in signals for different purposes.

1. Write a Python program that creates a PyQt application with a push button. Display a message when the push button is clicked.

Click me to see the sample solution

2. Write a Python program that builds a PyQt application with two push buttons. Connect each button to a different slot function, and when clicked, have each button perform a unique action.

Click me to see the sample solution

3. Write a Python program that creates a one-line text editor where you can type text. Whenever you type something in that box, it should immediately show up somewhere else on the screen, like a label. Use PyQt module.

Click me to see the sample solution

4. Write a Python program that creates a sliding bar on the screen. The slider will display a number that shows where it is. Use the PyQt module.

Click me to see the sample solution

5. Write a Python program that creates a combo box with different items. When you select an item from the list, it should appear somewhere on the screen immediately. Use the PyQt module.

Click me to see the sample solution

6. Write a Python program that creates a button and when clicked it prints a message. Use the PyQt module.

Click me to see the sample solution

7.Write a Python program that creates a button and when clicked sends a message with a specific value. Use the PyQt module.

Click me to see the sample solution

8. Write a Python program that creates a notepad system where you can type, edit and display text. As you write, it should automatically count and show how many characters you've written. Use the PyQt module.

Click me to see the sample solution

9. Write a Python program that creates a simple calculator application and displays buttons for numbers and math operations. Use the PyQt module.

Click me to see the sample solution

10. Write a Python program that creates a PyQt application with a radio button group. When you select a radio button it should immediately show you which one you picked.

Click me to see the sample solution

11. Write a Python program that creates a window for an application. When you try to close the window (like clicking the X button), it should check if you're sure you want to close the application and ask for confirmation. Use the PyQt module.

Click me to see the sample solution

12. Write a Python program that creates an application with a window that displays the current time. Use the PyQt module.

Click me to see the sample solution

13. Write a Python program that creates a window with a checkbox, like a "yes" or "no" choice. When you click the checkbox to check or uncheck it, something should happen. Use the PyQt module.

Click me to see the sample solution

14. Write a Python program that creates an application with a menu. When we choose menu items, a specific message appears.

Click me to see the sample solution

15. Write a Python program that makes an application listen to keyboard shortcuts, like pressing a specific key combination. When you press that key combination, a message appears. Use the PyQt module.

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.