Python Articles

Page 144 of 855

How to keep selections highlighted in a Tkinter Listbox?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 2K+ Views

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 More

How to increase the font size of a Text widget?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 801 Views

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 More

How to hide or disable the mouse pointer in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 4K+ Views

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

How to have image and text in one button in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 6K+ Views

In Tkinter, we can add both an image and text to a button using the compound property. By default, when you add an image to a button, it hides the text. The compound property allows us to control the relative positioning of the image and text. Understanding the Compound Property The compound property accepts these values ? LEFT − Image on the left, text on the right RIGHT − Image on the right, text on the left TOP − Image above the text BOTTOM − Image below the text CENTER − Image overlaps the text ...

Read More

How to create a child window and communicate with parents in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 3K+ Views

Tkinter provides powerful features for creating multi-window applications. You can create child windows (also called dialog boxes) that communicate with their parent windows to share data and respond to user interactions. A child window in Tkinter is created using the Toplevel() constructor, which creates a new top-level window that can interact with its parent window. Basic Child Window Creation Here's how to create a simple child window and pass data from parent to child ? import tkinter as tk from tkinter import ttk # Create main window root = tk.Tk() root.geometry("400x200") root.title("Parent Window") ...

Read More

How to create a borderless fullscreen application using Python-3 Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 3K+ Views

In order to make a Tkinter window borderless and full-screen, we can use the utility method attributes('-fullscreen', True). Tkinter windows can be configured using functions and methods defined in the Tkinter library. Another similar method Tkinter provides to make the application window full-screen is overrideredirect(True). This method can be invoked only if the application needs to resize in its defined width and height only. Method 1: Using attributes('-fullscreen', True) The attributes('-fullscreen', True) method creates a true fullscreen window that covers the entire screen including the taskbar ? # Import the required Libraries from tkinter import ...

Read More

How to convert PDF files to Excel files using Python?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 35K+ Views

Python provides several libraries for handling file conversions. In this article, we'll learn how to convert PDF files to Excel format using the tabula-py module. The tabula-py library is built on Java technology and can extract tabular data from PDF documents and convert it into pandas DataFrames. Prerequisites Before working with tabula-py, ensure you have Java installed on your system, as the library depends on Java for PDF processing. Installation Install the required package using pip − pip install tabula-py Basic Syntax The main functions we'll use are − ...

Read More

How to add an image in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 4K+ Views

Adding images to Tkinter applications enhances the user interface and provides visual appeal. You can display images using PIL (Pillow) library with PhotoImage and Label widgets. Basic Image Display Here's a simple example that displays a fixed image in a Tkinter window ? import tkinter as tk from PIL import Image, ImageTk # Create main window root = tk.Tk() root.title("Image Display") root.geometry("400x300") # Load and display image try: # Load image using PIL img = Image.open("sample.jpg") # ...

Read More

How do you check if a widget has a focus in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 4K+ Views

In Tkinter, you can check if a widget has focus using the focus_get() method. This method returns the widget object that currently has focus, allowing you to compare it with your target widget to determine if it's focused. Using focus_get() Method The focus_get() method is called on the root window and returns the currently focused widget object. You can compare this returned object with your widget to check if it has focus ? import tkinter as tk # Create main window root = tk.Tk() root.geometry("400x300") root.title("Focus Check Example") # Create widgets entry1 = tk.Entry(root, ...

Read More

How do I get an event callback when a Tkinter Entry widget is modified?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 8K+ Views

Callback functions in Tkinter are used to handle specific events in widgets. You can add an event callback function to an Entry widget that triggers whenever the widget's content is modified. This is accomplished by creating a Tkinter variable (like StringVar) and using its trace() method to monitor changes. Basic Entry Widget Callback Here's how to create a callback that responds to Entry widget modifications − import tkinter as tk def callback(var): content = var.get() print(f"Entry modified: {content}") # Create main window win = tk.Tk() win.geometry("400x200") ...

Read More
Showing 1431–1440 of 8,549 articles
« Prev 1 142 143 144 145 146 855 Next »
Advertisements