Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Dev Prakash Sharma
Page 18 of 42
Read an image with OpenCV and display it with Tkinter
OpenCV is an Open Source Computer Vision library in Python which is widely used for Research purposes in Artificial Intelligence and Machine Learning. Computer Vision Library such as OpenCV deals with image processing. We can use OpenCV to read an image and further use it for development.Let us suppose that we want to create an application that reads an image and displays it in the window using OpenCV.Install OpenCV by using the following command −pip install opencv-pythonNext, follow the steps given below −Install OpenCV in the environment and import the library using import cv2.Import NumPy and PIL (Pillow Package) for image calculation.Load ...
Read MoreHide the console of an .exe file created with PyInstaller in Tkinter
To convert a standard Tkinter application into a window executable file, we generally use thePyintsaller package. It converts the application file into an executable application. However, we notice that when we open the executable (or .exe) file, it displays a command shell before opening the application window. We can hide or avoid the console by specifying pyinstaller --oneline filename --windowed command.ExampleIn this example, we will create an .exe file of the following program using PyInstaller.app.py#Import the required libraries from tkinter import * #Create an instance of Tkinter Frame win = Tk() #Set the geometry win.geometry("700x350") #Set the ...
Read MoreHow to remove the title bar in a Tkinter window without using overrideredirect() method?
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 MoreWhat's the difference between Tkinter's Tk and Toplevel classes?
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 MoreDefault window color Tkinter and hex color codes in Tkinter
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 MoreHow to compile a Python 3 app to an .exe using Tkinter?
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 MoreTkinter dropdown Menu with keyboard shortcuts
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 MoreHow to bind events to Tkinter Canvas items?
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 MoreHow to specify where a Tkinter window should open?
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 MoreHow to bind the spacebar key to a certain method in Tkinter?
Tkinter methods can be bound with the Keys or Mouse to perform certain operations or events in an application. Let us suppose for a particular application, we want to bind the Key such that it will perform a certain operation. We can bind any key to a particular operation or event by defining the bind(, callback) method.ExampleIn this example, we will create rectangles of random width and height by using random Module in Python. So, whenever we will press the Key, it will generate some random shapes on the screen.#Import the required Libraries from tkinter import * import random ...
Read More