Tkinter in macOS

Salman Mehmood Apr 01, 2022
Tkinter in macOS

In this demonstration, we will talk about how we can install Tkinter on a macOS and how to define a virtual environment on a mac operating system. So now, we will be installing Tkinter directly from the macOS terminal that allows you to use Tkinter in your Python shell.

Create Tkinter GUI Application with mac Operating System in Python

Before we begin, if you don’t have Python installed, click on this link. You can quickly learn how to download and get started in Python.

To ensure that we have Python installed correctly and get started, let’s hit command and Space to open up our mac search feature, then let’s type "terminal". Let’s type "python" within our terminal and then hit Tab; this should show you all of your Python additions.

So we can choose to work in the latest version of Python; let’s type the latest available version and hit Enter. This will show you information confirming that Python is installed correctly.

If we work with different Python versions, it is better first to create a virtual environment that will contain all of our project’s information. Now to create a Python virtual environment, let’s tell the terminal that we want to work with Python 3.9; this version could be different in your case.

python3.9 -m venv venv

So how do we go about entering that virtual environment? We’ll follow the below command and run it onto your terminal.

source venv/bin/activate

We can now see that we work within our terminal’s venv environment. Now that our virtual environment is created, there is not much more for us to do, as we know that the Tkinter is part of the standard Python library, meaning that we do not need to download any additional libraries.

So to test if Tkinter is installed correctly, let’s create a simple blank GUI. To do so, let’s import the tkinter library and create a few lines of code.

from tkinter import *

# create a GUI window widget
GUI = Tk()

GUI.mainloop()

If we run this code on our machine, this blank GUI window appearing is proof that Tkinter is now working in our newly created Python virtual environment, so we hope this has helped you get started with Tkinter on a mac operating system.

Salman Mehmood avatar Salman Mehmood avatar

Hello! I am Salman Bin Mehmood(Baum), a software developer and I help organizations, address complex problems. My expertise lies within back-end, data science and machine learning. I am a lifelong learner, currently working on metaverse, and enrolled in a course building an AI application with python. I love solving problems and developing bug-free software for people. I write content related to python and hot Technologies.

LinkedIn