tkinter is the most commonly used GUI module for Python. It provides a standard interface to the Tk GUI toolkit. To create a tkinter application, you import the tkinter module, create a main window container object, add widgets to the main window, apply event triggers to widgets, and run the main loop using mainloop(). There are different geometry managers like pack, grid, and place that control how widgets are organized in the parent window.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
106 views
Python GUI
tkinter is the most commonly used GUI module for Python. It provides a standard interface to the Tk GUI toolkit. To create a tkinter application, you import the tkinter module, create a main window container object, add widgets to the main window, apply event triggers to widgets, and run the main loop using mainloop(). There are different geometry managers like pack, grid, and place that control how widgets are organized in the parent window.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
Python GUI – tkinter
Python offers multiple options for developing GUI (Graphical
User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter is the fastest and easiest way to create the GUI applications. Creating a GUI using tkinter is an easy task. To create a tkinter app: 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. 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 it is ‘tkinter’. import tkinter There are two main methods used which the user needs to remember while creating the Python application with GUI. 1. 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 2. mainloop(): There is a method known by the name mainloop() is used when your application is ready to run. mainloop() is an infinite loop used to run the application, wait for an event to occur and process the event as long as the window is not closed. m.mainloop() import tkinter m = tkinter.Tk() ''' widgets are added here ''' m.mainloop() tkinter also offers access to the geometric configuration of the widgets which can organize the widgets in the parent windows. There are mainly three geometry manager classes class. 1. pack() method:It organizes the widgets in blocks before placing in the parent widget. 2. grid() method:It organizes the widgets in grid (table-like structure) before placing in the parent widget. 3. place() method:It organizes the widgets by placing them