- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to make a Button using the Tkinter Canvas widget?
The Canvas widget is one of the versatile widgets in Tkinter. It is used to create graphics, objects such as drawing shapes, arcs, animating objects, and more. We can add a Button in the Tkinter canvas by assigning the parent as the canvas in the Button object.
In this example, we have constructed a LabelFrame which contains a canvas. Initially, the Canvas widget will hold a set of Buttons in the range.
#import required libraries from tkinter import * from tkinter import ttk #Create an instance of Tkinter frame win= Tk() #Set the geometry of the window win.geometry("750x250") #Create a LabelFrame labelframe= LabelFrame(win) #Define a canvas in the window canvas= Canvas(labelframe) canvas.pack(side=RIGHT, fill=BOTH, expand=1) labelframe.pack(fill= BOTH, expand= 1, padx= 30, pady=30) #Create Button widget in Canvas for i in range(5): ttk.Button(canvas, text= "Button " +str(i)).pack() win.mainloop()
Running the above code will display a Window that contains some buttons defined in a Canvas.
- How to make a Tkinter widget invisible?
- How to update a Button widget in Tkinter?
- How to get the value of a button in the Entry widget using Tkinter?
- How to create a Button on a Tkinter Canvas?
- Embedding an Image in a Tkinter Canvas widget using PIL
- How to make a Tkinter canvas rectangle transparent?
- How to make the Tkinter text widget read only?
- Get the text of a button widget in Tkinter
- How do I get the background color of a Tkinter Canvas widget?
- How to clear the Entry widget after a button is pressed in Tkinter?
- How do you create a Button on a Tkinter Canvas?
- How to make a Button Hover to change the Background Color in Tkinter?
- How to center a Tkinter widget?
- How to set the text/value/content of an 'Entry' widget using a button in Tkinter?
- How to call a function using the OptionMenu widget in Tkinter?