Prerequisite : Introduction to pyqt-5
In this article, we will see how we can create a quarter(1/4) mile calculator using PyQt5. Quarter mile calculator is used to determine the terminal speed (trap speed) and quarter-mile elapsed time (ET) of a vehicle based on its weight and power.
Below image shows how the 1/4 mile calculator looks like :
The quarter-mile calculator employs three distinct empirical equations to determine the quarter-mile elapsed time (ET). These are as follows:
1. Roger Huntington’s Equation:
Time = 6.290 × (Weight / Power)^(1/3)
2. Geoffrey Fox’s Equations:
Time = 6.269 × (Weight / Power)^(1/3)
3. Patrick Hale’s Equations:
Time = 5.825 × (Weight / Power)^(1/3)
Note: Here weight is in Pound (lb) and power is in horsepower (hp) units.
GUI Implementation Steps :
1. Create a heading label that display the calculator name
2. Create label and combo box pair for selecting equation, label to show what user has to select and combo box to select
3. Similarly create a pair of label and line edit to get the weight and power of car
4. Create a push button to calculate the time
5. Create a label to show the calculated time
Back-End Implementation :
1. Make the combo box non editable
2. Make the line edit to accept only the number as input
3. Add action to the push button
4. Inside the push button action get the text of the line edits
5. Check if the line edit text is empty or zero then return so that function will not execute further
6. Convert the text value into integer
7. Get the selected option from the combo box and set constant value according to it
8. Calculate the time and show this value through the label
Below is the implementation :
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.