Creating a GUI with Dropdown Menus

Part 2 of creating a GUI to convert units.

Now you have a converter handy for converting MPa to psi. What if you want to convert between other units of pressure? Instead of hard-coding MPa and psi, you want to be able to give the user an OptionMenu of all of the available pressures from the Pint library. You will create a list of all available pressure units, then make two OptionMenus to let the user pick which pressures to convert between. The GUI will now look like this:

Column 1 Column 2 Column 3
Row 1 Label saying “Converter”
Row 2 Label saying “Convert” Entry field for inputting a str OptionMenu with all pressures
Row 3 Label saying “into”
Row 4 Label that will eventually have the computed result OptionMenu with all pressures
Row 5 Button saying “Calculate”

Let’s look at how Column 3 OptionMenus are created:

Get hands-on with 1400+ tech skills courses.