Skip to content
Related Articles

Related Articles

How do you create a Button on a tkinter Canvas?
  • Last Updated : 03 Jan, 2021

In this article, we will see how to create a button on a Tkinter Canvas.

The Canvas widget display various graphics on the application. It can be used to draw simple shapes to complicated graphs. We can also display various kinds of custom widgets according to our needs.

 It is used trigger any function which is presented in the code

Intro to code :

In this we try to create button on canvas widget. Firstly make canvas then place the button on the canvas.



Syntax:

C = Canvas(root, height, width, bd, bg)

Syntax:

button = Button ( root,height,width,bg,command)

Steps :

  1. Import tkinter from
  2. Then define the window size and other requirements.
  3. First create canvas from the above give syntax.
  4. With the help of place function in tkinter place the button.

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# import everything from tkinter module
from tkinter import *
  
root = Tk()
  
root.geometry('430x300')
  
title = Label(root, text="Geeksforgeeks", bg="green", font=("bold", 30))
title.pack()
c = Canvas(root, width=330, height=200, bg="red")
c.place(x=50, y=50)
btn = Button(root, text='Welcome to Tkinter!', width=40,
             height=5, bd='10', command=root.destroy)
  
btn.place(x=65, y=100)
  
root.mainloop()

chevron_right


OUTPUT:


Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :