Articles on Trending Technologies

Technical articles with clear explanations and examples

Placing plot on Tkinter main window in Python

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 03-May-2021 3K+ Views

Oftentimes, we need to deal with plots in our Tkinter GUI-based application. To support the plots for the available data points, Python provides a Matplotlib package that can be imported into the application easily. In order to add a plot for the given data points, we have to install several other packages such as NumPy along with Matplotlib. NumPy is a Python library that helps to deal with scientific calculation in the Data.ExampleIn this example, we will create data points for the car prices starting from (100000) with the units in the range of 1000 to 5000.#Import the required Libraries ...

Read More

How to show a window that was hidden using the "withdraw" method in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 03-May-2021 8K+ Views

Tkinter withdraw method hides the window without destroying it internally. It is similar to the iconify method that turns a window into a small icon. Let us suppose we want to reveal the hidden window during the execution of an application then we can use deiconify() method. It can be invoked with the window or frame of a widget in the application.ExampleIn this example, we will define a button in a Toplevel window (Popup Window) which can be the trigger to reveal the main window.#Import the library from tkinter import * from tkinter import ttk #Create an instance of Tkinter frame win= ...

Read More

How to draw images in the Tkinter window?

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

To process images with Tkinter and other Python packages, we generally refer to use Pillow Package or PIL in Python. It provides a way to load and process the images in the program wherever we need. Initially, we convert the image to an instance of PhotoImage object that allows images to be further used in many use cases. Further, the Canvas widget in Tkinter helps to draw the images in a Tkinter application, we can use the create_image(x, y, image_file) method to display the image in a particular application.Example#Import the required Libraries from tkinter import * from PIL import Image, ...

Read More

How Region of Interest (ROI) works in OpenCV using C++?

Ginni
Ginni
Updated on 03-May-2021 3K+ Views

To separate a particular portion from the image, we have to locate the area first. Then we have to copy that area from the main image to another matrix. This is how the ROI in OpenCV works.In this example, two matrices have been declared at the beginning. After that, an image named 'image_name.jpg' has been loaded into the 'image1' matrix. The next line 'image2=image1 (Rect(100, 100, 120, 120));' requires special attention. This line is cropping out the defined region of the image and storing it in the 'image2' matrix.The figure shows what we have done here with the 'Rect(100, 100, ...

Read More

How to stop Tkinter after function?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 03-May-2021 6K+ Views

Tkinter functions can be created with the help of threading concept where we define, when a function should run or stop. A Tkinter function can be scheduled using the after(time, callback) function.Let us suppose that we have created a callback function that forces the main window to be closed after some time. There might be times when we need to stop the scheduling of the function. In order to cancel or stop a particular schedule of a callback function, we can use after_cancel(widget) function.ExampleIn the given example, the script will close the main window after 3 seconds but after initializing ...

Read More

How to set the width of a Tkinter Entry widget in pixels?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 03-May-2021 12K+ Views

Tkinter has an Entry widget to accept single-line user input. It has many properties and attributes that can be used to configure the Entry widget. To change the size (width or height of the Entry widget), we can use Internal Padding Properties – ipadx and ipady. By defining the value of internal padding, we can actually change the width and height of the Entry widget.Example#Import the required Libraries from tkinter import * from tkinter import ttk #Create an instance of tkinter frame win = Tk() #Set the geometry of tkinter frame win.geometry("750x350") #Define a function to submit the validate the ...

Read More

How to remove focus from a Tkinter widget?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 03-May-2021 3K+ Views

To active the focus on a particular widget during the execution of a Tkinter program, we can use focus_set() method. Adding the focus creates a gray line around the widget and makes it visible to the user.There might be some cases when we need to remove the focus from the desired widget.This can be done either by removing the focus_set() property or switching the focus from one widget to another.Example#Import the required Libraries from tkinter import * from tkinter import ttk from tkinter import messagebox #Create an instance of Tkinter frame win = Tk() #Set the geometry of Tkinter ...

Read More

How do I find out the size of a canvas item in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 03-May-2021 3K+ Views

To find the minimum height and width of canvas items, we can use the bounding box property of Canvas. Basically, a bounding box property enables the canvas item to return the position inside the canvas. Initially, every item in the bbox(item) method defines the minimum and maximum width and height of the item.Example#Import required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Define the geometry of the window win.geometry("750x250") #Initialize a Canvas canvas= Canvas(win, width= 600, height= 200) #Add a text inside the Canvas text= canvas.create_text(300, 20, text= "This is a New Line Text", font=16, ...

Read More

How can I set the default value of my Tkinter Scale widget slider to 100?

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

Tkinter Scale Widgets are used to provide the visual representation of data items where we can modify or change the value of data items. In order to change the state of data or select multiple data in the field, we can use the Scale widget.The Scale Widget can be created by initializing a Scale(parent, from_, to, orient, options) constructor.However, sometimes we need to set the default value of the Tkinter Scale widget, which can be set by using the set(numeric_value) method.ExampleIn this example, we will create a scale widget that sets a default value for the slider.#Import the required Libraries ...

Read More

How can I put two buttons next to each other in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 03-May-2021 7K+ Views

Tkinter generally provides three general ways to define the geometry of the widgets. They are − Place, Pack, and Grid Management. If we use the Pack geometry manager, then place the two buttons in the frame using side property. It places the buttons horizontally stacked in the window in (Left, Right, Top and Bottom) direction. The side property maintains the same width and internal padding between all the adjacent widget in the application.Example#Import the required Libraries from tkinter import * from tkinter import ttk import random #Create an instance of Tkinter frame win = Tk() #Set the geometry of Tkinter frame ...

Read More
Showing 49711–49720 of 61,297 articles
Advertisements