Articles on Trending Technologies

Technical articles with clear explanations and examples

Program to merge strings alternately using Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 6K+ Views

Suppose we have two strings s and t. We have to merge them by adding letters in alternating fashion, starting from s. If s and t are not of same length, add the extra letters onto the end of the merged string. So, if the input is like s = "major" and t = "general", then the output will be "mgaejnoerral". Since t is larger than s, we have added extra part "ral" at the end. Algorithm To solve this, we will follow these steps − Initialize i := j := 0 ...

Read More

Program to find longest nice substring using Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 666 Views

A nice substring is one where every letter appears in both uppercase and lowercase. For example, "bBb" is nice because 'b' appears as both 'b' and 'B'. This tutorial shows how to find the longest nice substring in Python. Problem Understanding Given a string, we need to find the longest substring where every letter appears in both uppercase and lowercase forms. If multiple substrings have the same maximum length, return the one that appears first. Algorithm Approach We'll use a nested loop approach to check all possible substrings: For each starting position, build a ...

Read More

Program to find largest perimeter triangle using Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 647 Views

Suppose we have an array nums of positive lengths, we have to find the largest perimeter of a triangle by taking three values from that array. When it is impossible to form any triangle of non-zero area, then return 0. So, if the input is like [8, 3, 6, 4, 2, 5], then the output will be 19. Triangle Inequality Rule For three sides to form a triangle, they must satisfy the triangle inequality: the sum of any two sides must be greater than the third side. For sides a, b, c where a ≥ b ≥ ...

Read More

Creating scrollable Listbox within a grid using Tkinter

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

A Listbox widget displays a list of items such as numbers, employee names, or any collection of data. When dealing with long lists, we need scrollbars to navigate through all items effectively. By attaching a Scrollbar to a Listbox and configuring them properly, we can create a scrollable interface within a grid layout. Basic Scrollable Listbox Let's start with a simple scrollable Listbox containing numbers from 1 to 100 − # Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of Tkinter Frame win = Tk() win.title("Scrollable Listbox ...

Read More

Call a Function with a Button or a Key in Tkinter

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

In Tkinter applications, you can call functions when buttons are clicked or keys are pressed. This is achieved using the command parameter for buttons and the bind() method for key events. Calling a Function with Button Click The simplest way to call a function is by using the command parameter when creating a button ? # Import the required libraries from tkinter import * from tkinter import ttk from tkinter import messagebox # Create an instance of Tkinter Frame win = Tk() # Set the geometry of Tkinter Frame win.geometry("700x350") # Define a ...

Read More

How to clear Text widget content while clicking on the Entry widget itself in Tkinter?

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

The Tkinter Text widget is an input widget that supports multiline user input, functioning as a text editor. You can clear its content using the delete(0, END) method. Similarly, you can clear an Entry widget's content by clicking on it, achieved by binding a function to a click event. Example Here's how to create an Entry widget that clears its placeholder text when clicked ? # Import the required libraries from tkinter import * # Create an instance of Tkinter Frame win = Tk() # Set the geometry of Tkinter Frame win.geometry("700x250") # ...

Read More

How to change the Entry Widget Value with a Scale in Tkinter?

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

The Tkinter Entry widget accepts single-line user input and can be synchronized with a Scale widget to create an interactive value selector. By sharing a common variable between both widgets, changes to the Scale automatically update the Entry value. Key Components To link an Entry widget with a Scale widget, you need: IntVar() or DoubleVar() − A Tkinter variable shared between widgets textvariable parameter in Entry widget variable parameter in Scale widget Basic Example Here's how to create a synchronized Entry and Scale widget ? import tkinter as tk from tkinter ...

Read More

How to set the tab order in a Tkinter application?

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

The tab order in any GUI application determines which widget receives focus when the user presses the Tab key. In Tkinter applications, you can control this navigation order to improve user experience and accessibility. Understanding Tab Order By default, Tkinter sets the tab order based on the sequence in which widgets are created. However, you can customize this behavior using the lift() method to programmatically change the focus order. Example Here's how to create Entry widgets and modify their tab order ? # Import the required libraries from tkinter import * # Create ...

Read More

Keyboard shortcuts with Tkinter in Python 3

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

Tkinter provides built-in functionality for binding keyboard shortcuts to specific actions in your application. You can bind individual keys, key combinations, or even mouse buttons to callback functions that execute when the shortcut is triggered. Basic Keyboard Shortcut Example Here's how to create a simple keyboard shortcut that closes the application when Ctrl+X is pressed − # Import the Tkinter Library from tkinter import * # Create an instance of Tkinter Frame win = Tk() # Set the geometry of window win.geometry("700x350") # Define a callback function for exit def quit_program(event): ...

Read More

How to resize the background image to window size in Tkinter?

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

In order to work with images, Python provides the Pillow (PIL) package that enables applications to import and manipulate images. When creating Tkinter applications, you often want the background image to resize automatically with the window. To resize a background image dynamically to match the window size, follow these steps − Import the required libraries (tkinter and PIL). Create a Canvas widget and use create_image() to place the image. Define a function to resize the image based on window dimensions. Bind the resize function to the window's event. Example Here's a complete example ...

Read More
Showing 4641–4650 of 61,297 articles
« Prev 1 463 464 465 466 467 6130 Next »
Advertisements