Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
How to Bind Multiple Commands to Tkinter Button?
Next article icon

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 given syntax.
  4. With the help of place function in tkinter place the button.
Python3
# import everything from tkinter modulefromtkinterimport*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()
OUTPUT:


Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp