Tkinter canvas is the most versatile widget in the Tkinter library. It is used to create images, shapes, arcs, animating objects, and many more other works. In order to work and process the images, Python supports Pillow Package or PIL. We can add images in the canvas as the items using the create_image(width, height, image_location, options) method. We can also specify where the image should open in the window by defining the Positional arguments such as anchor(options) property.Example#Import the required Libraries from tkinter import * from PIL import Image, ImageTk #Create an instance of tkinter frame win = Tk() ... Read More
There are two types of Text editors that Tkinter supports -- the Entry widget and the Text widget. Tkinter text widgets are used to create the text editor where we can edit, add or delete the text whenever we need. We can create a text widget using the Text(parent) constructor. In order to insert a default text for the text widget, we can use the insert(INSERT, "text_to_insert") or insert("1.0", "text_to_insert") method after the text widget declaration.ExampleIn this example, we will insert the text at the beginning of the text box.#Import the required Libraries from tkinter import * #Create an instance ... Read More
Pillow package (or PIL) helps a lot to process and load images in Python projects. It is a free open-source library available in Python that adds support to load, process, and manipulate the images of different formats.In order to open the Image in Tkinter canvas, we have to first import the library using from PIL import Image, ImageTk command. To display the image in our Tkinter application, we can use the Canvas widget by specifying the image file in the create_image(x, y, image) method.Example#Import the required Libraries from tkinter import * from PIL import Image, ImageTk #Create an instance of ... Read More
Tkinter widgets are the building blocks of any Tkinter GUI application. It is one of the very useful components of the application that helps to structure the application functionality. Consider a case where we want to set the size (width and height) of any widget. Tkinter has built-in width and height properties defined in geometry manager. Each geometry manager has different ways to configure the widget’s property.For the pack geometry manager, we can specify the value of width in the constructor.However, there might be times when we want to add the advance padding (internal and external) in the widget which ... Read More
Tkinter has many inbuilt functions or methods that can be used to extend the functionality of any widget in the application. Sometimes, we need to change or modify the focus of any widget in the application which can be achieved by using the focus_set() method.This method sets the default focus for any widget and makes it active till the execution of the program.ExampleIn this example, we will set the focus on first Entry widget where we are required to Enter the name of the User.#Import the required Libraries from tkinter import * from tkinter import ttk #Create an instance of ... Read More
In order to manage too many widgets in the window, we can use Frame widgets in Tkinter. In order to place the widgets inside the frame widget, we have to set the relative width and height of the frame. To configure the relative height and width of the frame, we have to configure it using the place(relx, rely) method.Now, let us create a frame and add a button to it.Example#import required libraries from tkinter import * from tkinter import ttk #Create an instance of Tkinter frame win= Tk() #Set the geometry of the window win.geometry("750x250") #Create a LabelFrame ... Read More
The sizing property of all the widgets in the Tkinter frame is by default set to the size of the widgets themselves. The frame container shrinks or grows automatically to fit the widgets inside it. To stop allowing the frame to shrink or grow the widget, we can use propagate(boolean) method with one of any pack or grid geometry manager. This method stops the frame from propagating the widgets to be resized.There are two general ways we can define the propagate property, pack_propagate (False) – If the Frame is defined using the Pack Geometry Manager.grid_propagate (False) – If the Frame is ... Read More
A Menubar contains a set of Menu Item in which each Menu Item is defined for different functionalities or operations. Let us suppose that we want to update the label of Menu Bar Items, then we can use entryconfigure(item_number, options..) method in a callback. To update the Menu Items in the Menu Bar, we can add label in the above method.ExampleLet us create an application with a list of Menu Items in the Menu Bar. When we will click a Particular Item, it will change the text in it.#Import the required Library from tkinter import * #Create an Instance of tkinter frame ... Read More
In order to close or remove any widget in an existing Tkinter application, we can use the destroy() method. It terminates the widget process abruptly within the program. The method can be invoked with the specific widget we want to close.ExampleIn this example, we will create a button to remove the Label Widget from the application.#Import required libraries from tkinter import * from tkinter import ttk #Create an instance of Tkinter frame win= Tk() #Define the geometry of the window win.geometry("750x250") #Define a function to destroy the label widget def close_widget(): label.destroy() #Create a label label= Label(win, text= ... Read More
Tkinter ListBox widget is generally used for creating a list of items in the form of a list. The items can be chosen through the mouse buttons whenever we click a particular List Item. Each item in the ListBox is configured with the default color, which can be changed by defining the ‘background’ and ‘foreground’ color in itemconfig(options) method.ExampleIn this example, we will create a ListBox that contains a list of items. We will provide different colors to a few of the list items.#Import required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Define ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP