We'll use a few different features of TkInter to display our GUI. The first item every TkInter GUI needs is a root window, also known as the master, which acts as the top-level parent to any other items we add to the GUI. Within this window, we'll combine several objects that allow the user to interact with our interface, such as the Label, Entry, and Button items:
- The Label object allows us to place text labels that cannot be edited on the interface. This allows us to add titles or provide a description for objects that indicate what should be written to or displayed in the field.
- The Entry object allows the user to enter a single line of text as input to the application.
- The Button object allows us to execute commands when pressed. In our case, the button will call the appropriate function to convert a timestamp of theĀ specific format and update the interface with the returned value.
Using these three features, we've already introduced all of the GUI elements needed for our interface. There're many more objects available for use and they can be found in greater detail in the TkInterĀ documentation at https://docs.python.org/3/library/tkinter.html.
We'll be writing our code in a way that works with both Python 2 and Python 3. For this reason, in Python 2 (for example, version 2.7.15), we'll import Tkinter as follows:
>>> from Tkinter import *
For Python 3, for example, version 3.7.1, we'll instead import it as follows:
>>> from tkinter import *
To condense this, we can instead use the sys module to detect the Python version and import the proper module, as shown here:
import sys
if sys.version_info[0] == 2:
from Tkinter import *
elif sys.version_info[0] == 3:
from tkinter import *