Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Programming Articles
Page 384 of 2547
How to select at the same time from two Tkinter Listbox?
When building GUI applications with Tkinter, you may need to select items from multiple Listboxes simultaneously. By default, Tkinter's exportselection property causes selections to be cleared when you click on another widget. Setting exportselection=False maintains selections across multiple Listboxes. Understanding exportselection Property The exportselection property controls whether the selected items in a Listbox are exported to the system clipboard. When set to False, selections remain active even when interacting with other widgets. Example Here's how to create two Listboxes that maintain independent selections ? # Import Tkinter library from tkinter import * # ...
Read MoreHow to select a directory and store the location using Tkinter in Python?
Dialog boxes are essential components in GUI applications that enable user interaction. In Python's Tkinter, we can create file and directory selection dialogs using the filedialog module. This allows users to browse and select files or directories from their local system. Selecting a File Directory To select a directory (folder) instead of individual files, we use filedialog.askdirectory(). Here's how to create a simple directory selector ? # Import the Tkinter library from tkinter import * from tkinter import ttk from tkinter import filedialog # Create an instance of Tkinter frame win = Tk() win.title("Directory Selector") ...
Read MoreHow to reset the background color of a Python Tkinter button?
Tkinter buttons are useful for handling events within the application. We can configure the button properties such as text style, font-family, background color, text color, and text size using predefined properties. We can reset the background color and other properties by defining a callback function that uses the configure() method to modify the button's appearance. Basic Example Here's how to reset a button's background color when clicked ? # Import the tkinter library from tkinter import * # Create an instance of tkinter frame win = Tk() # Define the geometry of the ...
Read MoreHow to remove the outline of an oval in Tkinter?
With Tkinter canvas, we can draw shapes for 2D or 3D applications, create images, draw animations, and many more things. When creating an oval on the canvas, you might want to remove its outline for a cleaner aesthetic look. To remove the outline from shapes in the canvas, we can provide an empty string "" to the outline parameter in the drawing method. Syntax The create_oval() method accepts several parameters including outline ? canvas.create_oval(x1, y1, x2, y2, fill="color", outline="") Parameters x1, y1 − Top-left coordinates of the bounding rectangle x2, y2 − ...
Read MoreHow to pass an argument to the event handler in Tkinter?
In most situations, callback functions can refer to Instance Methods. An instance method accesses all its members and performs operations with them without specifying any arguments. However, there are cases where we need to pass arguments to event handlers. This is common when multiple components share similar functionality but need different parameters. Lambda functions provide an elegant solution for passing arguments to Tkinter event handlers. Using Lambda Functions Lambda functions create anonymous functions that can capture and pass arguments to event handlers. Here's how to pass arguments to button click events ? import tkinter as ...
Read MoreHow to open a new window by the user pressing a button in a tkinter GUI?
Tkinter creates a default window (i.e., master or root window) for every application. In tkinter, we can create a popup window or child window by defining a Toplevel(master) constructor. This will allow the tkinter application to create another window which can be resized dynamically by defining its size property. Basic Syntax To create a new window, use the following syntax ? new_window = Toplevel(parent_window) new_window.geometry("widthxheight") new_window.title("Window Title") Example In this example, we have created a button widget that will open a new window with a text label ? # Import tkinter ...
Read MoreHow to list available font families in Tkinter?
Tkinter font property is one of the most valuable properties used to customize a widget's default font. We have already seen many fonts used in widgets, but sometimes it's complicated to determine which fonts are available in the Tkinter library. Python Tkinter is specific about font selection, and we can create an application to list all available fonts. To use the font library, we need to import it in our environment ? from tkinter import font Steps to Create the Font List Application There are several steps to create this application ? ...
Read MoreHow to keep selections highlighted in a Tkinter Listbox?
In Tkinter applications, you might need to keep selections highlighted in a Listbox while users interact with other widgets. By default, when you click on another widget, the Listbox loses its selection highlighting. The exportselection property solves this problem by controlling whether the selection should remain visible. Understanding exportselection The exportselection parameter determines whether the Listbox selection should be exported to the system's selection mechanism. When set to False, selections remain highlighted even when focus moves to other widgets. Syntax Listbox(parent, exportselection=False) Example: Multiple Listboxes with Persistent Selections Here's how to create ...
Read MoreHow to increase the font size of a Text widget?
We can customize the Tkinter widget by modifying the value of its properties such as font-family, text-size, width, the height of the frame, etc. Tkinter Text widgets are generally used for accepting multiline user input. It is similar to a standard text widget. To configure the text properties of a widget, we can use the font('font-family font-size font-style') attribute by defining its font-family, font-size, and the font style. Basic Example Here's how to create a Text widget with customized font size ? # Import tkinter library from tkinter import * # Create an instance ...
Read MoreHow to hide or disable the mouse pointer in Tkinter?
Tkinter provides built-in functionality to control window components including the mouse cursor. To hide or disable the mouse pointer in a Tkinter application, you can use the config(cursor="none") method on the root window. Syntax The basic syntax to hide the mouse pointer is − window.config(cursor="none") Example Here's a complete example that creates a window with a hidden mouse pointer − # Import tkinter library from tkinter import * from tkinter import ttk # Create an instance of Tkinter frame or window win = Tk() # Set the geometry of ...
Read More