Stack Exchange
multiple buttons on a tkinter canvas
I need multiple buttons on a canvas in Python Tkinter. The purpose is to draw connection lines among the buttons. My code:
from tkinter import *

root=Tk()
convas = Canvas(root)
convas.pack()
button1 = Button(text = "button 1")
button1.configure(width = 0, activebackground = "#D2D2D2", relief = GROOVE)
button1_window = convas.create_window(10, 10, anchor=NW, window=button1)
button1.update()
print (button1.winfo_geometry())

button2 = Button(text = "button 2")
button2.configure(width = 0, activebackground = "#D2D2D2", relief = GROOVE)
button2_window = convas.create_window(10, 50, anchor=NW, window=button1)
button2.update()
print (button2.winfo_geometry())
root.mainloop()

running this code, I always just got button 1 in the canvas although I tried to adjust the location in the create_window function, and the anchor=. the button 2 does not show in the canvas at all.
The two prints return:


62x26+10+10
  1x1+0+0.

Based on the output 1x1+0+0, the button 2 seems not being rendered. what I am doing wrong?
EDIT:
My mistake:
button2_window = convas.create_window(10, 50, anchor=NW, window=button1)

should be 
button2_window = convas.create_window(10, 50, anchor=NW, window=button2)


Your second button code in line 14 says window=button1. Change it to:
button2_window = convas.create_window(10, 50, anchor=NW, window=button2)

So that button2 shows up on its window like this:

