Basic Introduction To Tkinter

Tkinter



Introduction to Python GUI



- Python provides various options for developing graphical user interfaces (GUIs). Most important are listed below.  

Tkinter:- It is the easiest among all to get started with. It is Python’s standard GUI (Graphical User Interface) package. It is the most commonly used toolkit for GUI Programming in Python.  

JPython:- It is the Python platform for Java that is providing Python scripts seamless access o Java class Libraries for the local machine.  

wxPython:- It is open-source cross-platform GUI toolkit written in C++. It one of the alternatives to Tkinter, which is bundled with Python.
-There are many other interfaces available for GUI. But these are the most commonly used ones.

Python GUI Programming - Tkinter



- It is the standard GUI toolkit for Python.
- It was written by Fredrik Lundh.  
- Python when combined with Tkinter provides a fast and easy way to create GUI applications.  Tkinter provides a powerful object-oriented interface to the Tk GUI toolkit.  
- Creating a GUI application using Tkinter is an easy task.

Perform the following steps:- 

To create a tkinter:  




1).Importing the module – tkinter  
2).Create the main window (container) 
3).Add any number of widgets to the main window  
4).Apply the event Trigger on the widgets.
How To Install Tkinter :-

To see if you have Tkinter, launch python; then at the Python prompt, type: -
import Tkinter  
Or in Python 3: import tkinter

sudo apt-get install python-tk (for version 2)

sudo apt-get install python3-tk (for versoin 3)



There are two main methods used you the user need to remember while creating the Python application with GUI.

Tk(screenName=None,  baseName=None,  className=’Tk’,  useTk=1): 

To create a main window, tkinter offers a method ‘Tk(screenName=None,  baseName=None,  className=’Tk’,  useTk=1)’. To change the name of the window, you can change the className to the desired one.

The basic code used to create the main window of the application is:

    m=tkinter.Tk() where m is the name of the main window object

mainloop():-

- There is a method known by the name mainloop() is used when you are ready for the application to run. 
-  mainloop() is an infinite loop used to run the application, wait for an event to occur and process the event till the window is not closed.

    m.mainloop()

Example:
import tkinter 
m = tkinter.Tk()  
m.mainloop()



To Next Artical We Discuss About How to Use Pack,grid And Place Method In Python...



Check Out Our Python ALL Post In Just One Click....


Don't Forget to Share your Opinion About This post in Comment Section, Your One Comment Will Not only Make Our day But will Make our Year. And Do mention Of you have any ideas for our Blog:)

Post a Comment

11 Comments