GUI Programming in Python.
Introduction:. A graphical user interface is an application that has buttons, windows, and lots of other widgets that the user can use to interact with your application. A good example would be a web browser. It has buttons, tabs, and a main window where all the content loads. In GUI programming, a top-level root windowing object contains all of the little windowing objects that will be part of your complete GUI application. These windowing objects can be text labels, buttons, list boxes, etc.These individual little GUI components are known as widgets..
Python offers multiple options for developing GUI (Graphical User Interface). The most commonly used GUI method is tkinter. Tkinter 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 since Tkinter is the Python interface to Tk (Tea Kay), it can be pronounced as Tea-Kay-inter. i.e tkinter = t k inter..
tkinter - GUI for Python:. Python provides the standard library tkinter for creating the graphical user interface for desktop based applications. Developing desktop based applications with tkinter is not a complex task. A Tkinter window application can be created by using the following steps. Import the tkinter module. Create the main application window. Add the widgets like labels, buttons, frames, etc. to the window. Call the main event loop so that the actions can take place on the user's computer screen..
Importing tkinter is same as importing any other module in the python code. Note that the name of the module in Python 2.x is ‘Tkinter’ and in Python 3.x is ‘tkinter’. import tkinter (or) from tkinter import * After importing tkinter module we need to create a main window, tkinter offers a method ‘Tk()’ to create main window. The basic code used to create the main window of the application is: top = tkinter.Tk() (or) top=Tk() After creating main window, we need to add components or widgets like labels, buttons, frames, etc. After adding widgets to main window, we need to run the application, tkinter offers a method ‘mainloop()’ to run application. The basic code used to run the application is: top.mainloop ().
Example:. tkndemo.py. import tkinter. top = tkinter.Tk() top.title("Welcome").