Tuesday 17 July 2018

Install and use Tkinter in ubuntu

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.

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.
raghavareddy@raghavareddy:~$ python

raghavareddy@raghavareddy:~$ python
Python 2.7.3 (default, Oct 26 2016, 21:01:49) 
[GCC 4.6.3] 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()


No comments:

Post a Comment