Tkinter is Python's inbuilt GUI module. It comes with Python's standard library. It is used to create cross-platform desktop GUI applications. It is lightweight and easy to use compared to other GUI modules available in python. In this answer, we'll learn to create and use the Canvas
widget in Tkinter.
The Canvas
widget provides an area to place shapes and complex layouts in Tkinter.
Canvas()
#import tkinter module import tkinter as tk #create window window = tk.Tk() #provide size to window window.geometry("300x300") #create canvas c = tk.Canvas() #create circle shape c.create_oval(90,90,190,190, fill = "orange") c.pack() window.mainloop()
Line 5: We create an instance of the Tkinter class Tk()
and assign it to window
variable.
Line 8: We set the size of the window as 300x300
pixels using the geometry()
method.
Line 11: We create a canvas using the Canvas
widget.
Line 14: We create a circle shape using the method create_oval()
method provided by the Canvas
widget.
Free Resources