...

/

Creating a GUI with Hard-Coding

Creating a GUI with Hard-Coding

Part 1 of creating a GUI to convert units.

We'll cover the following...

We need the Tkinter and Pint libraries:

import tkinter as tk
import pint

Some people use the convention from tkinter import * which imports everything from Tkinter without having to use the syntax tkinter.blah. I prefer to import libraries the usual way (import tkinter as tk) to avoid any potential namespace conflicts. This alternative syntax could create weird conflicts if Tkinter had a function called blah(), for example, and you unknowingly decided to create a different function called blah().

Using Tkinter

When making a GUI with Tkinter, you need to decide if you are going to arrange elements by gridding them with grid() or packing them with pack(). Pack() packs the elements sequentially as you create them, while grid() allows you to grid according to row number and column number. You will use grid() in all of your examples. If you mix grid() and pack(), your program will either error out, or it will run in an infinite loop but not ...