Difference Between Focus and Focus_Set Methods in Tkinter

Dev Prakash Sharma
Updated on 18-Jun-2021 14:03:56

2K+ Views

Focus is used to refer to the widget or window which is currently accepting input. Widgets can be used to restrict the use of mouse movement, grab focus, and keystrokes out of the bounds. However, if we want to focus a widget so that it gets activated for input, then we can use focus.set() method. focus() is sometimes referred to as focus_set().focus_set() focuses on the widget when its window or widget gets focus.Example# Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter frame or window win=Tk() # Set the size of ... Read More

Change Text of Tkinter Listbox Item

Dev Prakash Sharma
Updated on 18-Jun-2021 13:56:14

1K+ Views

To display a list of items in the application, Tkinter provides a Listbox widget. It is used to create a list of items vertically. When we want to change the text a specific Listbox item, then we have to first select the item by iterating over the listbox.curselection() and insert a new item after deletion. To insert a item in the list, you can use listbox.insert(**items).Example# Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter frame or window win=Tk() # Set the size of the window win.geometry("700x350") # Create ... Read More

Delete and Edit Items in Tkinter Treeview

Dev Prakash Sharma
Updated on 18-Jun-2021 13:54:55

18K+ Views

Tkinter Treeview widget is used to display the data in a hierarchical structure. In this structure, each row can represent a file or a directory. Each directory contains files or additional directories. If we want to create a Treeview widget, then we can use Treeview(parent, columns) constructor to build the table.The Treeview widget items can be edited and deleted by selecting the item using tree.selection() function. Once an item is selected, we can perform certain operations to delete or edit the item.Example# Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter ... Read More

Get Coordinates on Scrollable Canvas in Tkinter

Dev Prakash Sharma
Updated on 18-Jun-2021 13:51:49

2K+ Views

The canvas widget has two coordinate systems: (a) Window coordinate system and (b) canvas coordinate system. The window coordinate system always starts from the leftmost corner (0, 0) in the window, while the canvas coordinate system specifies where the items are actually placed in the canvas.To convert the window coordinate system to canvas coordinate system, we can use the following two methods, canvasx(event.x) canvas(event.y)If we consider the case for the window coordinate system, then mouse events occur only in the window coordinate system. We can convert the window coordinate to a canvas coordinate system.ExampleIn this application, we will get the ... Read More

Widget Rowconfigure vs Grid Rowconfigure in Tkinter

Dev Prakash Sharma
Updated on 18-Jun-2021 13:51:32

6K+ Views

While building an application with Tkinter, we can use many components and widgets to extend the application. To render the widgets in the application, we use the Geometry Manager.The geometry manager configures the widget position and size within the window. The Grid Geometry manager treats the widget to place in rows and columns.If we want to span the widget and extend in one more cell or column, we use widget.rowconfigure() or widget.grid_rowconfigure(). It takes params such as weight and row/col value.The widget.rowconfigure() is sometimes used in place of widget.grid_rowconfigure(). Using these methods will allow the widget to have a weight property ... Read More

Play Sound When a Tkinter Button is Pushed

Dev Prakash Sharma
Updated on 18-Jun-2021 13:51:06

3K+ Views

Python has many inbuilt libraries and modules that are used for building various application interfaces and components. Pygame is one of the python modules which is used to design and build video games and music. It provides a mixture to handle all sound related activities. Using music sub-module, you can stream mp3, ogg, and other variety of sounds.To create an application that plays some sound on clicking a button, we have to follow these steps, Make sure that Pygame is installed in your local machine. You can install pygame using pip install pygame command.Initialize Pygame mixture by using pygame.mixture.init()Create a button widget which is ... Read More

Button Hover to Change Background Color in Tkinter

Dev Prakash Sharma
Updated on 18-Jun-2021 13:50:50

1K+ Views

A Button widget in Tkinter has many inbuilt features which can be used to configure and perform a certain task in the application. In order to run a particular event in the application, we can use the bind("", callback) method to bind a function or event with the button. To add the hover property in the Button, we can use  and  parameters in the bind function.Example# Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter frame or window win=Tk() # Set the size of the window win.geometry("700x350") def change_bgcolor(e):   ... Read More

Bind Multiple Events with One Bind in Tkinter

Dev Prakash Sharma
Updated on 18-Jun-2021 13:50:34

4K+ Views

For a particular application, if we want to perform multiple tasks with the help of buttons defined in it, then we can use the bind(Button, callback) method which binds the button and the event together to schedule the running of the event in the application.Let us suppose we want to bind multiple events or callback with a single , then we have to first iterate over all the widgets to get it as one entity. The entity can be now configurable to bind the multiple widgets in the application.Example# Import the required libraries from tkinter import * from tkinter import ... Read More

Open Excel Spreadsheet in Treeview Widget in Tkinter

Dev Prakash Sharma
Updated on 18-Jun-2021 13:50:17

8K+ Views

An Excel Spreadsheet contains a set of information stored in the form of rows and columns. We can display and use the spreadsheet data in the Tkinter application using Treeview widget. The Treeview widget in Tkinter helps users to add and manipulate the data in the form of a table. However, to analyze and manipulate a large set of data, Python provides Pandas library which gives access to many inbuilt functions and methods to perform data analysis.For this example, we will follow these steps to display the Excel Data in Tkinter, Import the required Libraries such as Numpy, Pandas, and filedialog.Add a ... Read More

Best Way to Show Data in a Table in Tkinter

Dev Prakash Sharma
Updated on 18-Jun-2021 13:49:57

7K+ Views

Generally, we represent data in the form of tables. A table contains a set of rows and columns. Data gets stored sequentially in the form of rows and columns in a table.Let us suppose that we are building a Tkinter application such that we have to store the Student’s data somewhere in a table. The table structure contains 3 columns to store the First Name, Last Name, and Roll Number of students. To display this type of information, Tkinter provides a Notebook widget where we can store our data in the form of a Table.Example# Import the required libraries from tkinter ... Read More

Advertisements