October 8, 2021

Python - simple GUI

Still using Python 3.9.7. I set up the following trivial GUI. It works right away under linux. A host of python packages are installed by default and I don't have to install them by hand.
#!/bin/python3

# Tom Trebisky  9-29-2021
# Just an experiment to see if I can make a simple file
# open dialog -- and I can!
# Best of all, it works perfectly without any fiddling
# on windows, which is exactly what we hope for with Python.

import tkinter as tk
from tkinter import filedialog

root = tk.Tk()
root.withdraw()

file_path = filedialog.askopenfilename()

print ( file_path )

What about on Windows

Apparently tkinter comes already installed with a Windows install of python. The official word is that tkinter is just part of the Python distribution on Windows, which is both surprising and pleasing.

Also note that tkinter is the name you use with Python 3, whereas with Python 2 you would have used Tkinter. If nothing else this is a quick way to glance at somebody elses script and determine if it is Python 2 or 3.

git pull
python opener.py
It works! I find this surprising (and nice).

I am curious about the exact nature of tkinter in the Python world. I have read misinformation that tkinter drags in Tcl and Tk under the hood. Maybe this was true long ago, but at this point tkiner is a standard part of the python interpreter with no Tcl in sight! I am not clear if and how it shadows Tk development in the Tcl world or whether it has forked in its own direction. By and large I don't deeply care, but am glad that Tcl is not lurking anywhere.


Feedback? Questions? Drop me a line!

Tom's Mineralogy Info / tom@mmto.org