Show Percentage in Matplotlib Pie Chart

Rishikesh Kumar Rishi
Updated on 26-Oct-2021 13:02:12

3K+ Views

In this article, we can create a pie chart to show our daily activities, i.e., sleeping, eating, working, and playing. Using plt.pie() method, we can create a pie chart with the given different data sets for different activities.StepsCreate a list of days, i.e., [1, 2, 3, 4, 5]. Similarly, make lists for sleeping, eating, playing, and working. There is an activities list that keeps “sleeping”, “eating”, “working” and “playing”.Make a list of colors.Use plt.pie() method to draw the pie chart, where slices, activities, colors as cols, etc. are passed.Set a title for the axes, i.e., “Pie Chart”.To show the figure ... Read More

Draw an Arc on a Tkinter Canvas

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 12:58:44

8K+ Views

The Canvas is a rectangular area intended for drawing pictures or other complex layouts. You can place graphics, text, widgets or frames on a Canvas.To draw an arc on a tkinter Canvas, we will use the create_arc() method of the Canvas and supply it with a set of coordinates to draw the arc. We can use create_arc() to create an arc item, which can be a chord, a pieslice, or a simple arc.Steps −Import the required libraries and create an instance of tkinter frame.Set the size of the frame using root.geometry method.Create a Canvas widget and set its height and ... Read More

Get Rid of Widget Border in Tkinter

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 12:55:08

12K+ Views

Tkinter comes with different types of widgets such as Button, Entry, Frame, Label, Radiobutton, Scrollbar, etc. Widgets are standard graphical user interface (GUI) elements that display information or help users interact with the system.In this example, we will see how to get rid of the border from a canvas, Entry fields, labels, and buttons.Steps −Import the required libraries and create an instance of tkinter frame.Set the size of the frame using root.geometry method.Next, create a Canvas and set the border width of the canvas with "bd" attribute. Then, use the "highlightthickness" attribute to define whether you want to show the ... Read More

Embedding an Image in a Tkinter Canvas Widget Using PIL

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 12:51:09

3K+ Views

The Pillow library in Python contains all the basic image processing functionality. It is an open-source library available in Python that adds support to load, process, and manipulate the images of different formats.Let's take a simple example and see how to embed an Image in a Tkinter canvas using Pillow package (PIL). Follow the steps given below −Steps −Import the required libraries and create an instance of tkinter frame.from tkinter import * from PIL import Image, ImageTkSet the size of the frame using root.geometry method.Next, create a Canvas widget using canvas() function and set its height and width.Open an image ... Read More

Run an Infinite Loop in Tkinter

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 12:48:38

8K+ Views

To run an infinite loop in Tkinter, we will use the after method to call a method recursively after a specified time period until the user decides to stop the loop. Let's take a simple example and see how to start and stop an infinite loop.Steps −Import the required libraries and create an instance of tkinter frame.Set the size of the frame using win.geometry method.Next, create a user-defined function "infinite_loop" which will call itself recursively and print a statement on the window.Define two more user-defined functions, start() and stop(), to control the infinite_loop. Define a global variable "condition". Inside start(), ... Read More

Determine Position of a Toplevel in Tkinter

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 12:45:08

2K+ Views

To place objects in the middle of a frame, we can use the place method. Let's take an example and see how it's done.Steps −Import the required libraries and create an instance of tkinter frame.Set the size of the frame using win.geometry method.Next, create a button and label it.Set the position of the buttons using the place method by supplying the x and y coordinate values.Place the center of the widget at a relative x and y position of 0.5 of button widget (relx=0.5, rely=0.5). Set the anchor at the center by supplying "anchor=CENTER"Finally, run the mainloop of the application ... Read More

Place Objects in the Middle of a Frame Using Tkinter

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 12:40:58

4K+ Views

To place objects in the middle of a frame, we can use the place method. Let's take an example and see how it's done.Steps −Import the required libraries and create an instance of tkinter frame.Set the size of the frame using win.geometry method.Next, create a button and label it.Set the position of the buttons using the place method by supplying the x and y coordinate values.Place the center of the widget at a relative x and y position of 0.5 of button widget (relx=0.5, rely=0.5). Set the anchor at the center by supplying "anchor=CENTER"Finally, run the mainloop of the application ... Read More

Position Buttons on a Tkinter Window

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 12:38:26

13K+ Views

To set the position of a button, we use the place method of button widget. The place method takes the x and y coordinates of the button.Steps −Import the required libraries and create an instance of tkinter frame.Set the size of the frame using win.geometry method.Next, create multiple buttons and name them "Button-1", "Button-2", etc.Set the position of the buttons using the place method by supplying the x and y coordinate values.Finally, run the mainloop of the application window.Example# Import the Tkinter library from tkinter import * from tkinter import ttk # Create an instance of Tkinter frame win ... Read More

Bind Tkinter Event to Left Mouse Button Held Down

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 12:35:43

3K+ Views

To bind a Tkinter event to the left mouse button being held down, we can take the following steps −Create an instance of tkinter frame.Set the size of the frame using win.geometry method.Define an event handler "handler1" to print a statement when the mouse is moved with the left button being held down.Define another event handler "handler2" to print a statement when the mouse button is released.Use the bind method to bind with handler1.Use the bind method again to bind with hander2.Finally, run the mainloop of the application window.Example# Import required libraries from tkinter import * # ... Read More

Save Contents of a Textbox in Tkinter

Kiran Kumar Panigrahi
Updated on 26-Oct-2021 12:32:06

7K+ Views

To save the contents of a Textbox in Tkinter, we can take the following steps −Create an instance of tkinter frame.Set the size of the frame using win.geometry method.Define a user-defined method "open_text" to open a text file in "read" mode. Read the contents of the text file and save it in a variable called "content". Then, use the "insert" method to insert the contentin a Textbox.Next, define another user-defined method called "save_text" and in it, use the "write" method to save the contents of the textbox in the text file.Create a text widget using the Text method with specified ... Read More

Advertisements