We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Tkinter

Let's start by just making sure that your tkinter installation is working. Tkinter is a Python library that allows us to create simple graphical user interfaces (GUIs) for our programs. It's not game-specific like Pygame, instead its more tailored to creating desktop GUIs... but in our case we'll really just be using it as a simple canvas to draw lines on.

Assignment

For most systems, tkinter will work out of the box... but let's make sure that its working for you.

Run the following command in your terminal to see if it's installed:

python3 -m tkinter

You should see a little window pop up with some buttons inside. If you do, you're done, just submit the CLI tests. There's no penalty on failure for this lesson. Otherwise, continue.

Troubleshooting

If you're seeing an error like this:

ModuleNotFoundError: No module named '_tkinter'

You're missing the dependency. Check to see which version of Python you're using:

python3 --version

You should be on 3.10 or higher. If you're not, update your Python version and try python3 -m tkinter again.

If that's still not working, it's important to understand that tkinter depends on the Tcl/Tk library. Installing the tk-dev or python-tk packages are usually the easiest way to install and link it to your Python version. On Ubuntu (Linux), run:

sudo apt-get install python3-tk

On MacOS, make sure you have Homebrew installed, and then run:

brew install python-tk

Your versions of python-tk and Python should match!

If python3 -m tkinter still isn't working, try uninstalling and reinstalling Python so that it links to the now-available Tcl/Tk library.

If you're still having issues, try googling the error messages you're encountering or reach out for help in the Discord.