Python Articles

Page 543 of 852

What's the difference between Tkinter's Tk and Toplevel classes?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-May-2021 1K+ Views

Tkinter windows are created by initializing the Tk object first. It is the minimal part of any Tkinter application, which helps to instantiate the application. Tk helps to construct the basic building blocks of the application, such as an application window where all the widgets are placed.However,  Toplevel classes help to communicate through the internal widgets of the main application. One of the examples of toplevel classes is the Toplevel window that displays a child window other than the main window of the application. The Toplevel window works the same as the Tk, as it also can contain widgets and functionalities.Example#Import the required ...

Read More

Default window color Tkinter and hex color codes in Tkinter

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-May-2021 2K+ Views

A Tkinter window can be customized by adding the 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. Example# Import the required libraries from tkinter import * #Create an instance of Tkinter Frame win = Tk() #Set the geometry win.geometry("700x350") ...

Read More

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

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-May-2021 4K+ Views

Python is well-known for its rich library of extensions and packages. We can import and install the necessary packages from the library. However, if we require to run a Tkinter application with an executable file in Windows Operating System, then we can use the Pyinstaller package in Python. It converts a Python-based application to a native executable file (or.exe).Follow the steps to compile a Tkinter-based application into an executable file, Install Pyinstaller using 'pip install pyinstaller'.Open the Command or Shell in the same directory where the application file is located and run the file using the command, pyinstaller --onefile app.py. It ...

Read More

Tkinter dropdown Menu with keyboard shortcuts

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-May-2021 1K+ Views

A Dropdown Menu is nothing but a list of vertically stacked menu items that can be visible at the top Menu Bar of an application. We can create a Menu bar in a Tkinter application by creating an object of Menu() in which all the Menu items are present.There might be a case when we want to select the menu and perform some basic operations using Keyboard shortcuts. In order to bind the key to all the Menu, we use the bind_all(, callback) method.ExampleIn this example, the application window contains a Menu of items. When we press the combination of , it ...

Read More

How to bind events to Tkinter Canvas items?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-May-2021 2K+ Views

Tkinter events can be bound with the widgets to perform a set of operations on the widgets. To be more specific, we can also bind an event handler to Canvas Items by using bind(, callback) method. Binding the event with the canvas item makes a canvas item dynamic which can be customized by event handlers.Example#Import the required Libraries from tkinter import * import random #Create an instance of Tkinter frame win = Tk() #Set the geometry of the window win.geometry("700x350") #Crate a canvas canvas=Canvas(win, width=700, height=350, bg='white') def draw_shapes(e):    canvas.delete(ALL) canvas.create_oval(random.randint(5, 300), random.randint(1, 300), 25, 25, ...

Read More

How to specify where a Tkinter window should open?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-May-2021 11K+ Views

Tkinter window can be configured using the Geometry Manager. When we specify the main window using the geometry(width x height + position_right + position_left) method, then we generally enable the window to open in a particular position.Example#Import the required libraries from tkinter import * #Create an instance of Tkinter Frame win = Tk() #Set the geometry win.geometry("700x350+300+300") #Create a Label Label(win, text="This Window Opens at (300,300)", font=('Helvetica 15 bold')).pack(pady=30) win.mainloop()OutputRunning the above code will display a window at the specified position with a label text.

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 18-May-2021 742 Views

Suppose, we have two sparse vectors represented in two lists. We have to return the dot product of the two sparse vectors. The vectors are represented as objects, and the lists are stored in a member variable 'nums' in the objects.So, if the input is like vector1 = [1, 0, 0, 0, 1], vector2 = [0, 0, 0, 1, 1], then the output will be 1 The dot product is 1 * 0 + 0 * 0 + 0 * 0 + 0 * 1 + 1 * 1 = 1.To solve this, we will follow these steps −res := ...

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 18-May-2021 408 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.The boxes are put into the godown from left to right only.If ...

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 18-May-2021 225 Views

Suppose, we are provided an array that contains several strings that are 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 or else we return false.So, if the input is like dict = ['pqrs', 'prqs', 'paqs'], then the output will be True. The output produced is True because the strings listed in the input all differ in index 1. So, if any two pairs are taken, there is a difference in the same position.To solve this, ...

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 18-May-2021 290 Views

Suppose, we are given a class called 'TestArray' that contains an 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 values p, q, r, s as input and works like this −if all the four values in the given indexes of the array are either 0 or 1, it returns 4.else if any three values in the given indexes of the array are the ...

Read More
Showing 5421–5430 of 8,519 articles
« Prev 1 541 542 543 544 545 852 Next »
Advertisements