GUI-Programming Articles

Page 11 of 25

How to get the absolute path of a file using tkFileDialog(Tkinter)?

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

Tkinter is a standard Python library used to create functional GUI applications. The tkinter.filedialog module provides functions for interacting with system files and directories, allowing users to select files through a dialog box. When you select a file using filedialog.askopenfile(), you can get its absolute path using os.path.abspath(file.name). This returns the complete file path from the root directory, which is useful for file processing operations. Syntax import os from tkinter import filedialog file = filedialog.askopenfile(mode='r') absolute_path = os.path.abspath(file.name) Example Here's a complete example that opens a file dialog and displays the absolute ...

Read More

How to change ttk.Treeview column width and weight in Python 3.3?

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

To display large datasets in a Tkinter application, we can use the ttk.Treeview widget. The Treeview widget allows us to represent data in a tabular format with customizable columns and rows. To configure the column width and behavior of the Treeview widget, we use the column() method with width and stretch properties. These properties control how columns are sized and whether they resize with the window. Column Configuration Parameters The main parameters for column configuration are − width − Sets the initial column width in pixels stretch − Controls whether the column expands to fill ...

Read More

How to fit Tkinter listbox to contents?

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

Tkinter offers Listbox widgets which are very useful for displaying a large set of data items in list format. To fit a listbox to its contents, we can use the configure() method with the width parameter set to 0. Understanding Listbox Width Configuration The width property defines the width of the listbox widget in characters. When we set width=0, the listbox automatically adjusts its width to match the longest item in the list. Example Here's how to create a listbox that fits its contents ? # Import the required libraries from tkinter import * ...

Read More

How to package a Tkinter program to share with people?

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

Tkinter is a cross-platform GUI toolkit for Python used to create desktop applications. To share your Tkinter applications with others who don't have Python installed, you need to package them into executable files. This process converts your Python script into a standalone application that runs without requiring Python or additional dependencies on the target machine. Python provides several packaging tools, with PyInstaller being one of the most popular choices. PyInstaller creates executables for Windows, macOS, and Linux, making your applications accessible across different operating systems. Installing PyInstaller First, install PyInstaller using pip − pip install ...

Read More

Forcing Tkinter window to stay on top of fullscreen in Windows 10?

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

To render widgets in a Tkinter application, we generally use the mainloop() function which helps to display the widgets in a window. In many cases, tkinter windows display behind other windows or programs. While switching to other programs or windows, it can be difficult to find and switch back to the Tkinter window again. We can force our tkinter window to stay on top of other windows or programs by creating a function and defining the win.lift() method in a loop. In the loop, it will execute the win.after() function to ensure that the tkinter window always stays on ...

Read More

How to force Tkinter text widget to stay on one line?

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

Tkinter text widget can be configured by using the configure(**options) function. We can use it to configure the background color, foreground color, wrapping and other properties of the text widget. The wrap property of the Text widget controls how text wraps when it reaches the edge of the widget. By default, text wraps to the next line, but we can prevent this behavior to keep text on a single line. Understanding Text Wrapping Options The Text widget supports three wrap modes ? wrap=WORD − Wraps text at word boundaries (default) wrap=CHAR − Wraps text at ...

Read More

How to fully change the color of a Tkinter Listbox?

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

Tkinter Listbox widgets are very useful for displaying a large set of data items in list format. To change the appearance of the entire Listbox, including background and text colors, we can use the configure(**options) method to modify the widget's properties. Basic Color Configuration The most common approach is using the configure() method to set background, foreground, and other visual properties − # 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 ...

Read More

How to update information in the grid in Tkinter?

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

When working with Tkinter applications that use the Grid Geometry Manager, you often need to update widget properties dynamically. This can be accomplished using the configure(**options) method. The key is to assign your widgets to variables during creation, giving you global access to modify their properties later. Basic Widget Configuration Here's how to create a widget and update its properties − import tkinter as tk # Create the main window root = tk.Tk() root.geometry("700x350") root.title("Grid Information Update Example") # Create a label widget and assign to variable label = tk.Label(root, text="This is Houston Control. ...

Read More

Moving balls in Tkinter Canvas

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

Tkinter is a standard Python library used to create GUI-based applications. To create a simple moving ball application, we can use the Canvas widget which allows users to add images, draw shapes, and animate objects. Key Components The application consists of the following components − A Canvas widget to draw the oval or ball in the window A move_ball() function that updates the ball's position and handles collision detection with canvas walls The canvas.after() method to schedule regular position updates Speed variables to control ...

Read More

How to capture events on Tkinter child widgets?

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

When building interactive Tkinter applications, you often need to capture events on child widgets like buttons, listboxes, or entry fields. This involves creating callback functions that respond to user interactions such as clicks, selections, or key presses. Understanding Event Handling Event handling in Tkinter works through callback functions − functions that execute when specific events occur. You connect these functions to widgets using parameters like command for buttons or by binding events directly. Example: Capturing Listbox Selection Events Let's create a Listbox widget that captures selection events. When a user selects an item and clicks a ...

Read More
Showing 101–110 of 242 articles
« Prev 1 9 10 11 12 13 25 Next »
Advertisements