Python Articles

Page 563 of 852

How can I resize the root window in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 21-Apr-2021 4K+ Views

In this example, we will see how to resize a tkinter window using the geometry manager. Tkinter geometry manager is generally used to configure the width and height of a tkinter window.The geometry(width, height)method takes width and height as instances and resizes the window accordingly. We can also define the position of the tkinter window by adding geometry(width x height, X, Y) where x and y are horizontal and vertical positions of the window.Example#Import tkinter library from tkinter import * from tkinter import ttk #Create an instance of tkinter frame or window win= Tk() #Set the geometry of tkinter frame ...

Read More

Get the text of a button widget in Tkinter

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 21-Apr-2021 13K+ Views

Let us suppose that for a particular application, we want to retrieve the button value by its name. In such cases, we can use the .cget() function. Every tkinter widget supports the .cget() function, as it can be used to retrieve the widget configuration such as value or name.ExampleIn this particular example, we will create a button and then store the button text in a variable "mytext". Using the variable, we will display the text in a Label widget.#Import tkinter library from tkinter import * from tkinter import ttk #Create an instance of tkinter frame or window win= Tk() #Set ...

Read More

Get Application Version using Python

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 21-Apr-2021 2K+ Views

In software industries, whenever developers add a new feature, fix bugs in a particular application, they name the application to a new version, as it helps to recognize the recently updated features in that application.Using Python, we can get the version of any application. We will use pywin32 to interact with the executable files. It provides access to the win32 API which gives the ability to create COM and objects.First, install the required package by typing pip install pywin32 in the command shell.Import Dispatch to get the version number of the application.Create a variable to store the location of the ...

Read More

Disable Exit (or [ X ]) in Tkinter Window

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 21-Apr-2021 9K+ Views

The window manager implements the Tkinter window control icons. To hide and show the Tkinter window control icons, we can use the built-in function, which describes whether we want to disable control icons’ functionality.To disable the Exit or [X] control icon, we have to define the protocol() method. We can limit the control icon definition by specifying an empty function for disabling the state of the control icon.Example#Import the tkinter library from tkinter import * from tkinter import ttk #Create an instance of Tkinter frame win= Tk() #Define the geometry of the function win.geometry("750x250") def close_win():    win.destroy() def disable_event(): ...

Read More

Convert Images to PDFs using Tkinter

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 21-Apr-2021 660 Views

Python is a scripting language and thus, it helps in many ways to create file converters such as CSV to PDF, PDF to DOC, and vice-versa. With the help of certain libraries, we can also create an application that converts images into PDF. To create such an application, we use the img2pdf module in Python. It helps to parse the image binary and converts it into PDFs.We will follow these steps to create an application, First, make sure the system has img2pdf requirements already in place. Type pip install img2pdf on your terminal to install the package. Import img2pdf in ...

Read More

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

AmitDiwan
AmitDiwan
Updated on 19-Apr-2021 937 Views

When it is required to sort a list of tuples in increasing order based on last element of every tuple, a method is defined, that iterates over the tuple and performs a simple swap to achieve the same.Below is the demonstration of the same −Example Live Demodef sort_tuple(my_tup):    my_len = len(my_tup)    for i in range(0, my_len):       for j in range(0, my_len-i-1):          if (my_tup[j][-1] > my_tup[j + 1][-1]):             temp = my_tup[j]             my_tup[j]= my_tup[j + 1]         ...

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 19-Apr-2021 479 Views

When it is required to find the sum of a list where the specific element is sum of first few elements, a method is defined, that takes list as parameter. It uses list comprehension to find the cumulative sum.Below is the demonstration of the same −Example Live Demodef cumulative_sum(my_list):    cumulative_list = []    my_length = len(my_list)    cumulative_list = [sum(my_list[0:x:1]) for x in range(0, my_length+1)]    return cumulative_list[1:] my_list = [10, 20, 25, 30, 40, 50] print("The list is :") print(my_list) print("The cumulative sum is :") print (cumulative_sum(my_list))OutputThe list is : [10, 20, 25, 30, 40, 50] The cumulative ...

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 19-Apr-2021 1K+ Views

When it is required to find all numbers in a range where there are perfect square, and sum of digits in the number is less than 10, list comprehension is used.Below is the demonstration of the same −Example Live Demolower_limit = int(input(“Enter the lower range: “)) upper_limit = int(input(“Enter the upper range: “)) my_list = [] my_list = [x for x in range(lower_limit,upper_limit+1) if (int(x**0.5))**2==x and sum(list(map(int,str(x))))

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 19-Apr-2021 3K+ Views

When it is required to create a list of tuple, and have the first element as the number, and the second element as the square of the element, list comprehension can be used.Below is the demonstration of the same −Example Live Demomy_list = [23, 42, 67, 89, 11, 32] print(“The list is “) print(my_list) print(“The resultant tuple is :”) my_result = [(val, pow(val, 2)) for val in my_list] print(my_result)OutputThe list is [23, 42, 67, 89, 11, 32] The resultant tuple is : [(23, 529), (42, 1764), (67, 4489), (89, 7921), (11, 121), (32, 1024)]ExplanationA list is defined, and is displayed on ...

Read More

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

AmitDiwan
AmitDiwan
Updated on 19-Apr-2021 978 Views

When it is required to find the second largest number in a list using bubble sort, a method named ‘bubble_sort’ is defined, that sorts the elements of the list. Once this is done, another method named ‘get_second_largest’ is defined that returns the second element from the end as output.Below is the demonstration of the same −Example Live Demomy_list = [] my_input = int(input("Enter the number of elements...")) for i in range(1, my_input+1):    b=int(input("Enter the element..."))    my_list.append(b) for i in range(0, len(my_list)):    for j in range(0, len(my_list)-i-1):       if(my_list[j]>my_list[j+1]):          temp=my_list[j]       ...

Read More
Showing 5621–5630 of 8,519 articles
« Prev 1 561 562 563 564 565 852 Next »
Advertisements