Python program has different modules that need to be installed using a command prompt rather than downloading and installing the said modules. One of these modules is Tkinter which can be installed with a pip.
So, if you are specialized in the Tkinter python library you’d need to install the module or library on your Windows or macOS depending on your OS before you can import from Tkinter* on your Windows to run your Tkinter program codes.
Therefore, here in this article, you will learn how to install Tkinter on Windows using your Windows command prompt.
What is Tkinter?
Tkinter is a python programming library or module bound to the Tk GUI toolkit. It’s referred to as the standard interface to the TK GUI toolkit. Tkinter is python programming’s de facto standard GUI.
And to install Tkinter is quite simple on almost all the popular OS because it’s included in the standard python software for Windows, macOS, and Linux so you can easily install it library or module using commands with the help of your OS command prompt.
However, once you have successfully installed the Tkinter module on your device you will then need to use the import command to make the library or module callable on a python editor such as Pycharm.
Meanwhile, Pycharm isn’t the online python editor you can use. Thonny is also a good python editor. For windows, you can use Sublime text (a free text editor).
Recommended: 10 Websites for Learning Programming Languages from the Basic
How to Install Tkinter on Windows
We will use the Windows command to install the Tkinter modules on your Windows. Meanwhile, you first need to install Python 3 on your Windows for this module to work.
The following steps aid your Tkinter installation process on your Windows once you can confirm that you have installed Python on your Windows.
- Press “Win + R” to open the “Run Dialog” box
- Type “cmd” without the quotes and click “OK.”
- Type “pip install tk” without the quote.
- Click the “Enter” button.
- The command will download the Tkinter module and install it on your Windows.
You may see a successful message once the installation is completed. However, you may be prompted to upgrade your Tkinter to the latest version if you have installed the library before and you are trying to reinstall it again.
How to Upgrade Tkinter on Windows
You need to stay up-to-date at all times with your modules. If you have installed the Tkinter module before now you may be prompted to upgrade it to the latest version. So, follow the steps below to upgrade your Tkinter library module.
- Open your command prompt.
- type the command below and click on the enter button. You can also copy and paste.
python -m pip install --upgrade pip
- Click on the “Enter” button.
- The outdated version will be uninstalled and then install the latest version within a couple of seconds.
That is it. At this point, your Tkinter library module will be up-to-date.
How to Test Tkinter Installation
You need to confirm that the Tkinter library module has been successfully installed on your Windows computer before you write your first program.
- Launch your Python editor.
- Type the following command.
import Tkinter tkiner._test()
- You will see the image below to confirm that you have successfully installed the Tkinter module.
You can now start writing your Tkinter code. Let’s see how to write your first Tkinter code.
Note: Python 3 now use lowercase “t” when importing “Tkinter” instead of the capital “T” in Python 2.
How to Write your First Tkinter Code
After installing the Tkinter module library you can then write your first Tkinter code as a python programmer. And here is how you can import Tkinter and print your widget to the screen.
from tkinter import* root = Tk() myLabel = Label(root, text ="Welcome to Gadgetswright.") myLabel.pack() root.mainloop()
With this guide, you should have learnt how to install Tkinter on Windows, upgrade your Tkinter library module and write and print your first Tkinter code to the screen.