Articles on Trending Technologies

Technical articles with clear explanations and examples

Default window color Tkinter and hex color codes in Tkinter

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

A Tkinter window can be customized by adding properties and attributes such as background color, foreground color, width, height, etc. The color attribute in config() defines the default color of the main window. We can set the color of the window by defining either Hex Color (e.g., #000 for Black) or the Name of the color. Setting Background Color with Hex Codes Hex color codes provide precise color control using hexadecimal values. The format is #RRGGBB where RR, GG, and BB represent red, green, and blue components ? # Import the required libraries from tkinter ...

Read More

How to compile a Python 3 app to an .exe using Tkinter?

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

Converting a Python Tkinter application to an executable (.exe) file allows you to distribute your application without requiring Python installation on the target machine. PyInstaller is the most popular tool for creating standalone executables from Python applications. Installation and Setup First, install PyInstaller using pip − pip install pyinstaller Creating the Tkinter Application Let's create a simple Tkinter application that we'll convert to an executable file − # Import the required libraries from tkinter import * # Create an instance of Tkinter Frame win = Tk() # Set the ...

Read More

Tkinter dropdown Menu with keyboard shortcuts

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

A dropdown menu is a list of vertically stacked menu items that appears in the top menu bar of an application. We can create a menu bar in a Tkinter application by creating an object of Menu() which contains all the menu items. Sometimes we want to provide keyboard shortcuts to menu items for faster navigation. To bind keyboard shortcuts to menu items, we use the bind_all(, callback) method which applies the shortcut globally across the entire application. Basic Syntax Here's the basic structure for creating a dropdown menu with keyboard shortcuts ? # Create ...

Read More

How to bind events to Tkinter Canvas items?

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

Tkinter events can be bound with widgets to perform operations when user interactions occur. You can bind event handlers to Canvas items using the tag_bind() method, making canvas items interactive and dynamic. Binding Events to Canvas Items Use canvas.tag_bind(item_id, event, callback) to bind events to specific canvas items ? import tkinter as tk # Create window root = tk.Tk() root.title("Canvas Item Events") root.geometry("400x300") # Create canvas canvas = tk.Canvas(root, width=400, height=300, bg='white') canvas.pack() # Create canvas items circle = canvas.create_oval(50, 50, 150, 150, fill='lightblue', outline='blue', width=2) rectangle = canvas.create_rectangle(200, 50, 300, 150, fill='lightgreen', ...

Read More

How to specify where a Tkinter window should open?

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

Tkinter allows you to control where a window appears on screen using the geometry() method. The geometry method accepts a string format: "widthxheight+x_offset+y_offset" to set both size and position. Syntax window.geometry("widthxheight+x_offset+y_offset") Where: width, height − Window dimensions in pixels x_offset, y_offset − Position from top-left corner of screen Example Here's how to create a window that opens at position (300, 300) ? # Import the required libraries from tkinter import * # Create an instance of Tkinter Frame win = Tk() # Set the geometry win.geometry("700x350+300+300") ...

Read More

Program to find out the dot product of two sparse vectors in Python

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

A sparse vector is a vector where most elements are zero. The dot product of two vectors is calculated by multiplying corresponding elements and summing the results. For sparse vectors, we can optimize by skipping zero elements. Problem Statement Given two sparse vectors represented as lists, we need to calculate their dot product efficiently. The vectors are stored as objects with a nums attribute containing the list elements. Example If vector1 = [1, 0, 0, 0, 1] and vector2 = [0, 0, 0, 1, 1], the dot product is ? 1×0 + 0×0 + ...

Read More

Program to find out the number of boxes to be put into the godown in Python

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

Suppose we have two arrays containing integers. One list contains the height of some unit width boxes and another array contains the height of rooms in the godown. The rooms are numbered 0...n, and the height of the rooms is provided in their respective indexes in the array godown. We have to find out the number of boxes that can be pushed into the godown. A few things have to be kept in mind: The boxes can't be put one on another. The order of the boxes can be changed. ...

Read More

Program to find out if the strings supplied differ by a character in the same position in Python

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

Suppose, we are provided an array that contains several strings of the same length. We have to find out if any two of the supplied strings differ by a single character at the same position. If this difference is present, we return True, otherwise we return False. So, if the input is like words = ['pqrs', 'prqs', 'paqs'], then the output will be True. The output is True because all strings differ at index 1 ('q', 'r', 'a'), so any two pairs have a difference in the same position. Algorithm Steps To solve this, we will follow ...

Read More

Program to find out the index of the most frequent element in a concealed array in Python

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

Suppose we are given a class called TestArray that contains a private array which can only contain values 0 or 1, and two public member functions length() and query(). The function length() returns the length of the array and the function query() returns three different values comparing various values in the array. The function takes four indices p, q, r, s as input and works like this: If all four values at the given indices are the same (either all 0s or all 1s), it returns 4 If three values ...

Read More

Program to find out the index in an array where the largest element is situated in Python

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

Finding the index of the largest element in an array is a common problem. This tutorial demonstrates a unique approach where the array is encapsulated in a class and can only be accessed through specific member functions. Problem Statement We have a class called TestArray that contains an array not accessible by other classes. It provides two public member functions: length() − returns the length of the array compare(l, r, x, y) − compares sums of two subarrays The compare() function works as follows: ...

Read More
Showing 4671–4680 of 61,297 articles
« Prev 1 466 467 468 469 470 6130 Next »
Advertisements