Tkinter is a GUI module for python. you can use it to make GUI based applications in python. Tkinter provides several GUI widgets like buttons,menu, canvas,text,frame,label etc. to develop desktop applications.Though Tkinter is very popular and is included with windows, macosx install of python, There are also alternative choices like pyQt, wxPython…
In this tutorial we will see how to install it on linux and use it with an example.
First, check if you have python installed and also check its version
Open up your terminal and type python. if its installed then it will show information like version, help… check your version (mine is python 2.7.9)
aman@vostro:~$ python
Python 2.7.9 (default, Apr 2 2015, 15:33:21)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
If you don’t have python then install it
sudo apt-get install python
If you want to install python 3 then enter the following. If you are a newbie, I would recommend python 2 instead of python 3. Python 2 is still very popular and many apps are made on it. On ubuntu python2 is still the default
sudo apt-get install python3
Finally, Install Tkinter
sudo apt-get install python-tk
for python 3
sudo apt-get install python3-tk
How to Use it ?
Now, lets check if Tkinter is working well with this little example
open your terminal and enter into your python shell.
python
for python3
python3
if python was installed correctly you will get a >>> prompt.
aman@vostro:~$ python
Python 2.7.9 (default, Apr 2 2015, 15:33:21)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Now import Tkinter module. it wont show any error if it got imported correctly. NOTE: Make sure you type Tkinter (not tkinter) in python2 and tkinter (not Tkinter) in python3.
>>>import Tkinter
>>>
Now, just to check you can create an empty window using Tkinter.
>>>Tkinter.Tk()
to learn more about Tkinter, you can check out this tutorial on how to make a simple calculator using Tkinter:
http://www.techinfected.net/2016/02/make-gui-calculator-in-python-windows-linux.html
Thanks!