Found 604 Articles for Tkinter

How to fully change the color of a Tkinter Listbox?

Dev Prakash Sharma
Updated on 18-Jun-2021 14:17:22

2K+ Views

Tkinter Listbox widgets are very useful in the case of representing a large set of data items in form of list items. To configure the properties such as change the background color of the entire Listbox, we can use configure(**options) method to change the properties of the Listbox widget.Example# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win=Tk() # Set the size of the window win.geometry("700x350") # Add a Listbox widget with number as the list items listbox =Listbox(win) listbox.insert(END, "C++", "Java", "Python", "Rust", "GoLang", "Ruby", "JavScript", "C# ", ... Read More

How to update information in the grid in Tkinter?

Dev Prakash Sharma
Updated on 18-Jun-2021 14:17:06

479 Views

Let us suppose that a Tkinter application has widgets placed in the window using the Grid Geometry Manager. In order to change the properties of the Tkinter widgets, we can use configure(**options) method. While rendering the widgets in the window, we have to assign the constructor to a variable that gives access to change the widget’s property globally.Example# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win=Tk() # Set the size of the window win.geometry("700x350") # Add a Label widget and assign it to a new variable label=Label(win, ... Read More

Moving balls in Tkinter Canvas

Dev Prakash Sharma
Updated on 18-Jun-2021 14:16:47

2K+ Views

Tkinter is a standard Python library which is used to create GUI-based applications. To create a simple moving ball application, we can use the Canvas widget which allows the user to add images, draw shapes, and animating objects. The application has the following components, A Canvas widget to draw the oval or ball in the window.To move the ball, we have to define a function move_ball(). In the function, you have to define the position of the ball that will constantly get updated when the ball hits the canvas wall (left, right, top, and bottom).To update the ball position, we ... Read More

How to capture events on Tkinter child widgets?

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

460 Views

Suppose we are creating an application that interacts with the user clicks on the Button visible in the application. To understand how exactly events work, we have to create a callback function as well as a trigger that will execute an event. Whenever the user clicks the button, the event happens and it needs to be captured on the screen.ExampleIn this example, we will create a Listbox widget that will have a list of items in it. When we select an item, then it will capture what the user has clicked. To figure out the captured event, we can use ... Read More

Where to learn Tkinter for Python?

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

161 Views

Without a doubt, Python has a rich library of modules and extensions that can be used to structure an application the way we want. Tkinter is a well-known Python library that is used for building GUI-based desktop applications. Tkinter offers a robust and platformindependent window toolkit.Tkinter is a package that works on top of Tcl/Tk. It contains a set of implemented classes, wrappers which are written in the Tcl/Tk toolkit.We can use Tkinter for various creating applications such as images gallery, animating objects, Data Analysis, Scientific Calculation, Game Design, and Music applications.Tkinter offers a variety of modules, functions and widgets ... Read More

How to create a Tkinter toggle button?

Dev Prakash Sharma
Updated on 18-Jun-2021 14:14:23

3K+ Views

Python has a rich set of libraries and modules that can be used to build various components of an application. Tkinter is another well-known Python library for creating and developing GUI-based applications. Tkinter offers many widgets, functions, and modules that are used to bring life to the application visuals. We can create button widgets to perform certain tasks in an application.In this application, we will create a toggle button that will turn the On/ Off Night and Day mode of the application. To create a toggle button, we have to first render the image in a Label.We define buttons and ... Read More

What is the difference between focus and focus_set methods in Tkinter?

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

1K+ 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

How can I change the text of the Tkinter Listbox item?

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

885 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

14K+ 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

How to get coordinates on scrollable canvas in Tkinter?

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

1K+ 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

Advertisements