Sample Code for Conversion
We have a program designed to convert measurements from feet and inches to meters, and our goal is to transform it into a standalone executable. However, the process varies depending on the operating system: Windows, Mac, and Linux.
If you intend to create an executable for Windows, you must have access to a Windows computer. The same principle applies to Mac and Linux systems as well.
With this in mind, let's begin the process of creating the standalone executable on a Windows platform.
So, below are the sample code for conversion:
#file name: meter_converter.py
import functions
import PySimpleGUI as sg
label1 = sg.Text("Enter feet")
input1 = sg.Input(key="this_feet")
label2 = sg.Text("Enter inches")
input2 = sg.Input(key="this_inches")
button_convert = sg.Button("Convert")
output_meter = sg.Text(key="output", text_color="green")
convertor_layout = [[label1, input1], [label2, input2], [button_convert, output_meter]]
window = sg.Window("Convertor", layout=convertor_layout)
while True:
event, value = window.read()
print("1.event:", event)
print("2.value: ", value)
if event == sg.WINDOW_CLOSED: # Check if the window was closed
break
cal_feet = int(value["this_feet"])
cal_inches = int(value["this_inches"])
cal_meters = functions.convert_to_meter(cal_feet, cal_inches)
window["output"].update(value=str(cal_meters) + " meters")
window.close()
#file name: functions.py
def convert_to_meter(ft, inch):
"""convert answer to meter
receiving two arguments (feet, inches)
return 1 value (meter) """
meter1 = ft * 0.3048
meter2 = inch * 0.0254
meter = meter1 + meter2
return meter
if __name__ == "__main__":
dev_input_ft = int(input("Enter ft: "))
dev_input_inch = int(input("Enter inch: "))
dev_ans = convert_to_meter(dev_input_ft, dev_input_inch)
print("Answer in meter: ", dev_ans)
There will be two python file, meter_converter.py
and functions.py
. Make sure both files located in the same folder. Run the code in your system first to ensure no errors occur before converting it to standalone executable.