I want to make a button using the Tkinter canvas. But I can't find anything on how to do it. I've tried using the regular button widget, but those don't display nor do anything. If anyone has a way of doing, please tell me!
Asked
Active
Viewed 122 times
0
-
What exactly do you want? A button inside canvas? Or using canvas to simulate a button? – acw1668 Apr 15 '20 at 12:28
-
When you say "make a button using the Tkinter canvas", do you mean you want to create a custom button by drawing the borders and defining all of the key bindings and behaviors yourself? Or, are you asking how to add a standard `Button` to a canvas? – Bryan Oakley Apr 15 '20 at 14:31
-
I mean I want to draw all the stuff and do all that on my own. Also, is it possible to use an image as what you click on? – xbuzzzfarts152 Apr 15 '20 at 14:37
-
Yes, all that is possible. Why did you add `[ANSWERED]` to the title? It doesn't appear that you've accepted any of the answers. – Bryan Oakley Apr 15 '20 at 15:54
-
on another post some guy told be how to add buttons. – xbuzzzfarts152 Apr 15 '20 at 19:32
2 Answers
0
This works.
canvas.create_rectangle(x1, y1, x1+w, y1+h, fill=fill, tags=tag, width=width)
canvas.tag_bind(tag, "<Button-1>", function)
2nd line is key :)

rn0mandap
- 333
- 1
- 8
-1
This generates a button on a canvas, the canvas setting should be changeable without changing the button. Found here https://python-tricks.com/button-in-tkinter/
import tkinter as tk
screen = tk.Tk()
#Screen size
screen.geometry('300x300')
#Button
button_tk = tk.Button(screen, text="Hello")
button_tk.pack(side='top')
screen.mainloop()

UsernameTaken
- 26
- 2
-
The question specifically asks about using a `Canvas`, but your answer doesn't use a `Canvas`. – Bryan Oakley Apr 15 '20 at 15:54