Found 10476 Articles for Python

How to remove the icon from the title bar in Tkinter?

Dev Prakash Sharma
Updated on 25-May-2021 08:52:26

5K+ Views

To remove the default icon of the Tkinter window, we can use wm_attributes('type', 'value') method by specifying the type of property. In the following example, we will use '-toolwindow', a Boolean value that removes the icon associated with the title bar of the application.Example#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() win.geometry("700x350") #Create a Label to print the Name label= Label(win, text="This is a New Line Text", font= ('Helvetica 14 bold'), foreground= "red3") label.pack() win.wm_attributes('-toolwindow', 'True') win.mainloop()OutputWhen we run the above code, it will display a Tkinter window ... Read More

How to remove the title bar in a Tkinter window without using overrideredirect() method?

Dev Prakash Sharma
Updated on 25-May-2021 08:51:14

9K+ Views

To remove the title bar of a Tkinter window, we can use wm_attributes('type', 'value') method by specifying the type of property. In the following example, we will use 'fullscreen', a Boolean value that removes the title bar of the window.Example#Import the tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() win.geometry("700x350") #Create a Label to print the Name label= Label(win, text="This is a New Line Text", font= ('Helvetica 14 bold'), foreground= "red3") label.pack() win.wm_attributes('-fullscreen', 'True') win.mainloop()OutputRunning the above code will display a fullscreen window without the title bar.Read More

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

Dev Prakash Sharma
Updated on 25-May-2021 08:50:56

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
Updated on 25-May-2021 08:50:36

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
Updated on 25-May-2021 08:50:13

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
Updated on 25-May-2021 08:49:46

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
Updated on 25-May-2021 08:49:19

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
Updated on 25-May-2021 08:47:17

10K+ 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.

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

Arnab Chakraborty
Updated on 18-May-2021 12:14:56

696 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
Updated on 18-May-2021 12:14:14

371 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

Advertisements