SLC S21W1 || Creating Dynamic Interfaces with Python and Qt5

in hive-195150 •  4 days ago 

steemit-engagement-challenge-cover.jpeg

Greetings Steemit friends

Installation of the working environment including Thonny and Qt5 Designer.

So far, the order is not a problem. You can start with any, but take note you need both applications installed to complete the project. I start to get to the official website but clicking the link Qt Designer Download You have two options and you pick with respect to your OS(operating system).

Screenshot 2024-10-28 150502.jpg

After the download is complete, in most cases. you will find the downloaded setup in the download folder. Start the installation by double-clicking the setup.

Screenshot 2024-10-28 150636.jpg

Screenshot 2024-10-28 150718.jpg


Click Next, you have the option to choose where you want your installation files to be saved by clicking Browser. In most cases, and for me. I will not make changes, and continue with my installation.

Screenshot 2024-10-28 150752.jpg

Screenshot 2024-10-28 150826.jpg


Installation will take some minutes, and you will be notified when all is done. We can click finish and launch our application to make sure no installation file is missing along the line.

Screenshot 2024-10-28 150906.jpg



Thonny

Steps are not different, we start downloading our setup from the official website Thonny Website. Here the latest version is visible, with a different operating system. By moving your cursor over your OS, you have the option to download.

Screenshot 2024-10-28 150546.jpg

After the download is complete, in most cases. Move to the download folder and start installation by double click the setup.

Screenshot 2024-10-28 151520-th.jpg

Screenshot 2024-10-28 151834-th.jpg


You can continue by clicking next, not forgetting to check to accept to agreement. Most of the time it is advisable to read. let's continue by clicking the next.

Screenshot 2024-10-28 151908-th.jpg

Screenshot 2024-10-28 152319-th.jpg


click Browser if case you want to change the location of your installation files, or you want to change your project folder. let's continue by clicking the next.

Screenshot 2024-10-28 152408-th.jpg

Screenshot 2024-10-28 152721-th.jpg


All done, and our installation is completed.

Screenshot 2024-10-28 152829-th.jpg

Let's run the Thronny application and install the necessary packages for the project.

Screenshot 2024-10-28 152927-sec-th.jpg

Tools then select Manage Packages

Screenshot 2024-10-28 153119-sec-th.jpg

Type PyQt5 in the search bar for easy search

Screenshot 2024-10-28 153216-sec-th.jpg

Click on Install, and wait for a while.

Screenshot 2024-10-28 162032-sec-package.jpg

Screenshot 2024-10-28 162032-sec-package-2.jpg


Back to tools, then select Manage Packages. This time type pyqt5-tools in the search bar for an easy search.

Screenshot 2024-10-28 162032-sec-package-3.jpg

Screenshot 2024-10-28 162256-done.jpg


Click on Install, and wait for a while. Finally, we are good.


Task2: (3points)

Create a GUI in PyQt5 to display prime numbers between two values ​​a and b provided by the user.

Screenshot 2024-10-29 101415.jpg

Here we are to get the natural number which is great 1 and can't be gotten by multiplying two natural numbers. That is 1 and itself.

So, I will start with a function to check if the number is a prime number. The number must be greater than or equal to 2. Next, we check the number greater than 3, if we result in having a factor. Then the function will have to return false. Note that 2 is the only even prime.

Next, the function is to carry out the operations for the two numbers. I passed the two parameters a and b. I will use a for loop to check the numbers within the range a b and check if it is a prime number.

The next function is to make use of the UI, which I designed using Qt. the two input fields for a and b, make sure they are integers.

I did my first check, might not be necessary but recommended. This is to make sure both inputs are greater than 2. Next, I created a variable message to hold the function to get the prime numbers of the two inputs (a,b).

It values, if true, an array of numbers. One more thing, the checkbox we have on the user interfaces. If it checks, sort the message in descending order.

We have the RESET function, which we have in the course and the QUIT function.

Task3: (3points)

Develop a GUI in PyQt5 to perform the prime factorization of a positive integer greater than 1.

Screenshot 2024-10-29 101518.jpg

To have prime factorization, we will break the number into prime factors. I will start by creating a function to handle the logic. First, check if the number input is greater than or equal to 1. I set the variable factors to the array. I used the while loop to check if the range of the input value is divisible by 2. Next, after number 2, we have 3. Time to check odd numbers by dividing until the result is stocked.

Finally, the output of both the while and for loop is greater than 2. Then we have a list of factors of the inputted value (num)

Nex function makes use of the function above and ui completes the project. Here, prime^count comes into play to help in formatting the output. I hope from my explanation of a prime number, we understand why we have 1 after each prime.

Task4: (3points)

Develop a GUI in PyQt5 to calculate the number of combinations of p elements among n (notation ( C(n, p) )), where n > p > 0.

Screenshot 2024-10-29 101614.jpg

This task is a mathematical project and will need a formula.

                                       n!
        C(n,p)       =  --------------------------    
                             p! x (n-p)!

Not to crack my brain, I noticed I could make use of the math package.

Create the function to get the combination making use of the math.factorial function to ease the combination.

The next function is not different from the previous two projects. Here, I have updated values for n and p variables. A check to make sure (n <= 0 or p <= 0 or n < p) before going ahead to execute the function to get the combinations displayed.



Cheers
Thanks for dropping by
@fombae

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Upvoted! Thank you for supporting witness @jswit.

You have an interesting blog. Very good work. Everything is very clear.

Loading...