GUI Programming
Creating a Kilometer to Miles Converter
Lab Assignment Objectives
Understand the Application
For this GUI app you will create a kilometer to miles distance converter. Specifically we will write a class that will implement converting distances in kilometers to miles.
Implement a GUI app that contains:
Invoking the app, the user will be able to supply a kilometer value into the kilometer entry widget prompt.
When the user clicks the first button, Convert, the kilometers to miles conversion result will be displayed in an information dialog box. When the user clicks the second button, Quit, the app closes.
The Program Specification
Write a program that converts distances in kilometers to miles. The task for this lab is to develop an Object Oriented GUI application as a class that encapsulates the implementation of converting distances in kilometers to miles. Display the result in an info dialog box. Format floating point values to 2 decimal places.
Testing Specification
Create an instance of the Kilometer Converter GUI class to demonstrate your app.
Input Error Checking: Validate user Input into the entry widget (i.e. a valid kilometer value). Do check that the button clicked performs the correct action (i.e. the convert button invokes the callback function for the conversion, the quit button closes the app).
Test Run Requirements: Provide a screenshot of your GUI program console display.
What to Turn In
Deliverables: Submit 2 files:
Python Code (Yournamelab6.py) :
import tkinter as tk
from tkinter import messagebox
#root for creating a tkinter window
root= tk.Tk()
#we are creating a canvas window with width 450 and height
350
c1 = tk.Canvas(root, width = 450, height = 350, relief =
'raised')
c1.pack()
#here we are creating a label Kilometers to Miles Converter
text
l1 = tk.Label(root, text='Kilometers to Miles Converter')
#changing the font of the text to the helvetica with font size
14
l1.config(font=('helvetica', 14))
#here placing the text into our tkinter window
c1.create_window(200, 25, window=l1)
#here we are creating another label for enter a number
in kms
l2 = tk.Label(root, text='Enter a Number in (Kms)')
#changing the font of the text to the helvetica with font size
14
l2.config(font=('helvetica', 10))
#here placing the text Enter a number in km into our tkinter
window
c1.create_window(200, 100, window=l2)
#here e1 is input box
e1 = tk.Entry (root)
#adding e1 to the tkinter window
c1.create_window(200, 140, window=e1)
#here we are creating a function which will converts the
kilometers into miles
def convert ():
#we are getting input from e1 and store in the variable x1
x1 = e1.get()
#here 1 km = 0.621371 miles then x km = x*0.621371 miles
y = float(x1)*0.621371;
z = str(x1)+" Kilometers is equal to "+str(y)+" Miles "
#we are adding result to the dialog box
messagebox.showinfo("Result",z)
#here we are adding two buttons one for quit the tkinter window
another for converting the value into miles
b1 = tk.Button(text='Convert', command=convert, bg='brown',
fg='white', font=('helvetica', 9, 'bold'))
c1.create_window(160, 180, window=b1)
b2 = tk.Button(text=' Quit ', command=root.destroy, bg='brown',
fg='white', font=('helvetica', 9, 'bold'))
c1.create_window(230, 180, window=2)
root.mainloop()
# Python Code :


Here Output :



GUI Programming Creating a Kilometer to Miles Converter Lab Assignment Objectives Understand the basics of tkinter...
Python 3+ (using TKinter): 1.) Develop new TKinter GUI widget class Ed that can be used to teach first-graders addition and subtraction. The GUI should contain two Entry widgets and a Button widget labeled "Enter". At start-up, your program should generate (1) two single-digit pseudorandom numbers a and b and (2) an operation op, which could be addition or subtraction—with equal likelihood—using the randrange() function in the random module. The expression a op b will then be displayed in the...
use this code of converting Km to miles , to create Temperature converter by using java FX import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.geometry.Pos; import javafx.geometry.Insets; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.control.Button; import javafx.event.EventHandler; import javafx.event.ActionEvent; /** * Kilometer Converter application */ public class KiloConverter extends Application { // Fields private TextField kiloTextField; private Label resultLabel; public static void main(String[] args) { // Launch the application. launch(args); } @Override public void start(Stage primaryStage) { //...
Use Kilometer Converter application code to write Temperature
Converter application to convert degrees Fahrenheit into degrees
Celsius ((F - 32)*5/9). It needs to be JavaFX
1 import javafx.application. Application; 2 import javafx.stage. Stage; 3 import javafx.scene. Scene; 4 import javafx.scene.layout.HBox; 5 import javafx.scene.layout. VBox; 6 import javafx.geometry.Pos; 7 import javafx.geometry.Insets; 8 import javafx.scene.control.Label; 9 import javafx.scene.control. TextField; 10 import javafx.scene.control.Button; 11 import javafx.event. EventHandler; 12 import javafx.event. ActionEvent; 13 14 ** 15 * Kilometer Converter application 16 17 18 public...
for python
Introduction The purpose of this assignment is to familiarize you with the writing Python scripts that demonstratest usage GUI programming. Long-Distance Calls A long-distance provider charges the following rates for telephone calls: Rate Category Daytime 6:00 a.m. through 5:59 p.m.) Evening (6:00 p.m. through 11:59 p.m.) Off-Peak (midnight through 5:59 a.m.) Rate per Minute $ 0.07 $ 0.12 $ 0.05 Write a GUI application that allows the user to select a rate category (from a set of radio...