Found 310 Articles for GUI-Programming

How to display an image/screenshot in a Python Tkinter window without saving it?

Dev Prakash Sharma
Updated on 06-Aug-2021 06:27:38

1K+ Views

Tkinter is a standard Python library that is used to create and develop GUI-based applications. To display an image, we use the PIL or Pillow library.Let us suppose that we want to create an application that will take a screenshot of the window and display the captured image in another window. To achieve this, we can follow the steps given below −Import the required libraries.Create a universal button to take the screenshot.Define a function to take the screenshot.In the given function, define the coords and region through which we want to take the screenshot.Create a Toplevel window and define a ... Read More

How to draw a line on a Tkinter canvas?

Dev Prakash Sharma
Updated on 06-Aug-2021 06:24:26

17K+ Views

Tkinter Canvas widget can be used for multiple purposes such as drawing shapes, objects, creating graphics and images. To draw a line on a Canvas, we can use create_line(x, y, x1, y1, **options) method.In Tkinter, we can draw two types of lines: simple and dashed. We can specify the type of line using the dash property.Example# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win=Tk() # Set the size of the tkinter window win.geometry("700x350") # Create a canvas widget canvas=Canvas(win, width=500, height=300) canvas.pack() # Add a line ... Read More

Resizing images with ImageTk.PhotoImage with Tkinter

Dev Prakash Sharma
Updated on 06-Aug-2021 06:22:43

19K+ Views

The PIL or Pillow library in Python is used for processing images in a Tkinter application. We can use Pillow to open the images, resize them and display in the window. To resize the image, we can use image_resize((width, height) **options) method. The resized image can later be processed and displayed through the label widget.ExampleLet us have a look at the example where we will open an image and resize it to display in the window through the label widget.# Import the required libraries from tkinter import * from PIL import Image, ImageTk # Create an instance of tkinter ... Read More

How to change Entry.get() into an integer in Tkinter?

Dev Prakash Sharma
Updated on 06-Aug-2021 06:20:46

15K+ Views

The Entry widget in Tkinter is generally used to accept one-line input in the text field. We can get the output from the Entry widget using .get() method. However, the .get() method returns the output in string format. For example, if the user types an integer number in the Entry widget, it gets converted to a string. To change the type of the Entry input into an integer, we can cast the string to an integer.ExampleIn this example, we have shown how to calculate the sum while taking an integer input from the user.# Import the required libraries from tkinter ... Read More

How to configure default Mouse Double-Click behavior in a Tkinter text widget?

Dev Prakash Sharma
Updated on 06-Aug-2021 06:15:17

422 Views

The Text widget in Tkinter is used to add a text editor-like functionality in the application. The Text widget supports multiline user input from the user. We can configure the text widget properties such as its font properties, text color, background, etc., by using the configure() method.The Text widget also provides tagging through which we can make a selection of text. To extend this functionality, we can also bind the Double-Click button that will possess the event for selecting a Word at a time.ExampleLet us have a look at the example, where we have disabled the double mouse-click button to ... Read More

How to hide a widget after some time in Python Tkinter?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:48:51

505 Views

Tkinter is a standard Python library for developing GUI-based applications. We can create games, tools, and other applications using the Tkinter library. To develop GUI-based applications, Tkinter provides widgets.Sometimes, there might be a requirement to hide a widget for some time. This can be achieved by using the pack_forget() method. When we pack the widget in the window using the various methods, we have to use the same method for hiding the widget.Example# Import the required libraries from tkinter import * from PIL import Image, ImageTk # Create an instance of tkinter frame or window win=Tk() # Set ... Read More

How to change the TKinter canvas line from dash to solid?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:46:48

440 Views

Canvas widget is one of the most widely used widgets for graphical representation in a Tkinter application. To display a line in the Canvas widget, we can use the built-in library method create_line(x1, y1, x2, y2, **options).We can also specify the type of line using the dash property. To change the line type from solid to dash dynamically, we can use configure() method. By passing an empty value to the dash property, we can change the line from solid to dash.ExampleLet us take an example to see how it works.# Import the required libraries from tkinter import * from tkinter ... Read More

How to get the current length of the Text in a Tkinter Text widget?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:44:28

2K+ Views

The Text widget in Tkinter supports multiline user input from the user. We can configure the Text widget properties such as its font properties, text color, background, etc., by using the configure() method.To create an application that will count the currently written characters in a Text widget, we can follow these steps −Create a Text widget and define its width and height properties.A label widget is needed to display the total count of the characters.Define an event with and functionality and that will show the updated character count in the label widget.The function will have a label configuration ... Read More

How to change the mouse pointer color in Tkinter?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:41:19

1K+ Views

Tkinter is a standard Python library for developing GUI-based applications. We can change the properties of its widgets by using the built-in functions and methods. In some applications, the properties affect the mouse pointer as well.Tkinter provides us a way to change the mouse pointer color in the window. To configure the mouse pointer color, we can specify the cursor value with (cursor type and its color). For example, to change the cursor color in a label widget, we can specify the value as, cursor="plus #aab1212" where "plus" defines the cursor type and #aab1212 is the Hex value of the ... Read More

How can I identify when a Button is released in Tkinter?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:34:36

2K+ Views

In Tkinter, events are generally called by buttons or keys. Whenever the user presses an assigned key or clicks an assigned button, the events get executed. To execute the events, we can bind a button or a key with the callback function.Consider an application where we need to trigger an event whenever we release the mouse button. This can be achieved by passing the parameter in the bind(, callback) method.Example# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win=Tk() # Set the size of the window win.geometry("700x350") ... Read More

Advertisements