Python Articles

Page 135 of 855

Creating Tkinter full-screen application

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

Tkinter initially creates a window that contains application components such as widgets and control bars. We can switch a native-looking application to a full-screen application by using the attributes('-fullscreen', True) method. To make the window full-screen, just invoke the method with the particular window. Basic Full-Screen Example Here's how to create a basic full-screen Tkinter application ? # Import tkinter library from tkinter import * # Create an instance of tkinter frame or window win = Tk() # Set the geometry of tkinter frame win.geometry("750x250") # Create a Text widget text = Label(win, ...

Read More

Convert Images to PDFs using Tkinter

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

Python is a scripting language that helps create various file converters. Using the img2pdf module and Tkinter, we can build a GUI application that converts multiple images into PDF format. The img2pdf library efficiently parses image data and converts it to PDF without quality loss. Installation First, install the required module ? pip install img2pdf Building the Image to PDF Converter We will create a Tkinter application with file selection dialog and conversion functionality ? from tkinter import * from tkinter import filedialog, messagebox from tkinter import ttk import img2pdf import ...

Read More

Sort a List of Tuples in Increasing Order by the Last Element in Each Tuple using Python program

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 951 Views

When working with lists of tuples, you often need to sort them based on the last element of each tuple. Python provides multiple approaches: using sorted() with a key function, the list.sort() method, or implementing a custom bubble sort algorithm. Using sorted() with Key Function The most Pythonic approach uses sorted() with a lambda function as the key ? data = [(1, 92), (34, 25), (67, 89)] print("Original tuple list:") print(data) # Sort by last element of each tuple sorted_data = sorted(data, key=lambda x: x[-1]) print("Sorted list of tuples:") print(sorted_data) Original tuple ...

Read More

Python Program to Find the Cumulative Sum of a List where the ith Element is the Sum of the First i+1 Elements From The Original List

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 494 Views

When it is required to find the cumulative sum of a list where the ith element is the sum of the first i+1 elements from the original list, we can use different approaches. The cumulative sum creates a new list where each element represents the running total up to that position. Method 1: Using List Comprehension This approach uses list comprehension with slicing to calculate cumulative sums ? def cumulative_sum(my_list): cumulative_list = [] my_length = len(my_list) cumulative_list = [sum(my_list[0:x:1]) for x in range(1, my_length+1)] ...

Read More

Python Program to Find all Numbers in a Range which are Perfect Squares and Sum of all Digits in the Number is Less than 10

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 1K+ Views

When it is required to find all numbers in a range that are perfect squares and the sum of digits in the number is less than 10, list comprehension is used. A perfect square is a number that can be expressed as the product of an integer with itself. Below is the demonstration of the same − Example lower_limit = 5 upper_limit = 50 numbers = [] numbers = [x for x in range(lower_limit, upper_limit + 1) if (int(x**0.5))**2 == x and sum(list(map(int, str(x)))) < 10] print("The result is:") print(numbers) Output The ...

Read More

Python Program to Create a List of Tuples with the First Element as the Number and Second Element as the Square of the Number

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 3K+ Views

When you need to create a list of tuples where each tuple contains a number and its square, Python provides several approaches. The most common methods are list comprehension, using loops, and the map() function. Using List Comprehension List comprehension provides a concise way to create the list of tuples ? numbers = [23, 42, 67, 89, 11, 32] print("The list is:") print(numbers) result = [(num, pow(num, 2)) for num in numbers] print("The resultant tuples are:") print(result) The list is: [23, 42, 67, 89, 11, 32] The resultant tuples are: [(23, 529), ...

Read More

Python Program to Find the Second Largest Number in a List Using Bubble Sort

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 993 Views

Finding the second largest number in a list can be accomplished using bubble sort to first arrange elements in ascending order, then accessing the second-to-last element. Bubble sort repeatedly compares adjacent elements and swaps them if they are in the wrong order. Understanding Bubble Sort Bubble sort works by comparing each pair of adjacent elements and swapping them if the first element is greater than the second. This process continues until no more swaps are needed. Bubble Sort Process Initial: ...

Read More

Python Program to Merge Two Lists and Sort it

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 2K+ Views

When it is required to merge two lists and sort them, Python provides several approaches. You can use list concatenation with the sort() method, or combine merging and sorting in one step using sorted(). Below is the demonstration of the same − Method 1: Using List Concatenation and sort() Example Define a function that merges two lists and sorts them in-place − def merge_list(list_1, list_2): merged_list = list_1 + list_2 merged_list.sort() return merged_list numbers_1 = [20, 18, 9, 51, 48, 31] ...

Read More

Python Program to Find the Gravitational Force Acting Between Two Objects

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 518 Views

When calculating the gravitational force between two objects, we can use Newton's Law of Universal Gravitation. This law states that every particle attracts every other particle with a force proportional to the product of their masses and inversely proportional to the square of the distance between them. The formula is: F = G × (m₁ × m₂) / r², where G is the gravitational constant (6.673 × 10⁻¹¹ N⋅m²/kg²). Example Here's how to calculate gravitational force using a Python function ? def find_gravity(m_1, m_2, r): G_val = 6.673*(10**-11) # Gravitational ...

Read More

Python Program to Check If Two Numbers are Amicable Numbers

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 934 Views

Amicable numbers are two different numbers where the sum of proper divisors of each number equals the other number. For example, 220 and 284 are amicable because the proper divisors of 220 sum to 284, and the proper divisors of 284 sum to 220. What are Proper Divisors? Proper divisors are all positive divisors of a number except the number itself. For example, proper divisors of 220 are: 1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110. Method 1: Using Mathematical Approach This method finds divisors efficiently by checking only up to the square ...

Read More
Showing 1341–1350 of 8,549 articles
« Prev 1 133 134 135 136 137 855 Next »
Advertisements