Server Side Programming Articles

Page 880 of 2109

Python to create a digital clock using Tkinter

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 3K+ Views

Python Tkinter can be used to create all kinds of GUI programs for desktop applications. In this article, we will see how to create a digital clock that displays the current time in hours, minutes, and seconds format with live updates. We use the time module to import the strftime() method, which formats the current time. The clock updates automatically every 200 milliseconds using a recursive function and Tkinter's after() method. Creating the Digital Clock Here's how to build a simple digital clock using Tkinter ? import time from tkinter import * # Create ...

Read More

Add style to Python tkinter button

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 4K+ Views

Tkinter has great support for creating GUI programs based on Python. It offers different ways of styling buttons on the Tkinter canvas based on font, size, color, and other properties. In this article, we will see how to apply styles to specific buttons or all buttons in general on the canvas using the ttk.Style class. Applying Style to Specific Buttons Let's consider the case when we have two buttons in the canvas and we want to apply styling only to the first button. We use a custom style name like 'W.TButton' as part of the configuration along with ...

Read More

Python - Filtering data with Pandas .query() method

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 3K+ Views

The Pandas .query() method provides a powerful way to filter DataFrame rows using a string-based query expression. It offers a more readable alternative to boolean indexing for complex filtering conditions. Basic Syntax The .query() method accepts a query string and optional parameters ? import pandas as pd # Create sample dataset data = { 'age': [25, 30, 35, 40, 45, 50, 55, 60, 65], 'salary': [30000, 45000, 55000, 65000, 70000, 80000, 85000, 90000, 95000], 'department': ['IT', 'HR', 'IT', 'Finance', 'HR', 'IT', 'Finance', 'HR', ...

Read More

Python - Filter out integers from float numpy array

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 564 Views

When working with NumPy arrays containing both floats and integers, you may need to filter out integer values for data cleansing purposes. This article demonstrates two effective methods to remove integers from a float NumPy array using astype comparison and modulo operations. Method 1: Using astype Comparison The astype function converts array elements to integers. By comparing the original array with its integer-converted version, we can identify which elements are not integers ? Example import numpy as np # Create array with mixed floats and integers data_array = np.array([3.2, 5.5, 2.0, 4.1, 5]) ...

Read More

Python - Filter dictionary key based on the values in selective list

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 2K+ Views

Sometimes in a Python dictionary we may need to filter out certain keys based on a selective list. This allows us to extract specific key-value pairs from a larger dictionary. In this article we will see how to filter dictionary keys using different approaches. Using List Comprehension with 'in' Operator In this approach we put the keys to be filtered in a list. Then iterate through each element of the list and check for its presence in the given dictionary. We create a resulting dictionary containing only these filtered key-value pairs ? Example # Original ...

Read More

Python - end parameter in print()

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 1K+ Views

The print() function in Python automatically adds a newline character () at the end of each print statement. However, you can customize this behavior using the end parameter to specify different ending characters or strings. Syntax print(value1, value2, ..., end='character_or_string') Default Behavior By default, print() ends with a newline character ? print("Welcome to") print("Tutorialspoint") Welcome to Tutorialspoint Using Space as End Character You can replace the newline with a space to print on the same line ? print("Welcome to", end=' ') print("Tutorialspoint") ...

Read More

Python - Difference in keys of two dictionaries

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 3K+ Views

Two Python dictionaries may contain some common keys between them. In this article we will find how to get the difference in the keys present in two given dictionaries. Using Set Difference Here we take two dictionaries and apply set function to them. Then we subtract the two sets to get the difference. We do it both ways, by subtracting second dictionary from first and next subtracting first dictionary from second. Those keys which are not common are listed in the result set ? Example dictA = {'1': 'Mon', '2': 'Tue', '3': 'Wed'} print("1st Dictionary:", ...

Read More

Python - Create a dictionary using list with none values

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 743 Views

Sometimes you need to create a dictionary from a list where each list element becomes a key with a None value. This is useful for creating placeholder dictionaries or initializing data structures. Python provides several methods to achieve this conversion. Using dict.fromkeys() The dict.fromkeys() method creates a dictionary with keys from an iterable and assigns the same value to all keys. By default, it assigns None ? days = ["Mon", "Tue", "Wed", "Thu", "Fri"] print("Given list:") print(days) result = dict.fromkeys(days) print("Dictionary with None values:") print(result) Given list: ['Mon', 'Tue', 'Wed', 'Thu', ...

Read More

Python - Convert given list into nested list

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 1K+ Views

Sometimes we need to convert list elements into individual sublists, creating a nested list structure. Python provides several approaches to achieve this transformation depending on your specific requirements. Using List Comprehension The simplest approach is to wrap each element in a list using list comprehension ? days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'] print("Given list:", days) # Convert each element to a sublist nested_list = [[item] for item in days] print("Nested list:", nested_list) Given list: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'] Nested list: [['Mon'], ['Tue'], ['Wed'], ['Thu'], ['Fri']] Using map() Function ...

Read More

Broadcasting with NumPy Arrays in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 312 Views

Broadcasting is a NumPy feature that allows arithmetic operations between arrays of different shapes without explicitly reshaping them. When arrays have unequal dimensions, NumPy automatically adjusts the smaller array's shape by prepending dimensions of size 1, enabling element-wise operations. Rules of Array Broadcasting NumPy follows these rules when broadcasting arrays ? Arrays with smaller ndim are prepended with dimensions of size 1 in their shape. The output shape in each dimension is the maximum of the input sizes in that dimension. An array can be used in calculation if its size in a particular dimension matches ...

Read More
Showing 8791–8800 of 21,090 articles
« Prev 1 878 879 880 881 882 2109 Next »
Advertisements