-2

I want a rectangle to appear WHEN I click on the button. But the rectangle appears even before I click.

from tkinter import *

def dessin():
    can.create_rectangle(50,50,70,70, fill = 'navy')

fen = Tk()
can = Canvas(fen, width= 100, height = 100, bg = 'ivory')
can.pack(side = TOP)
bou = Button(fen, text= 'envoyez le rectangle', command = dessin())
bou.pack(side = BOTTOM)
bou1 = Button(fen,text='Quitter', command = fen.quit)
bou1.pack(side=RIGHT)
fen.mainloop()
Josh Lee
  • 171,072
  • 38
  • 269
  • 275

1 Answers1

0

You need to pass the function itself, not the result of the function. So leave the () off.

bou = Button(fen, text= 'envoyez le rectangle', command = dessin)
Novel
  • 13,406
  • 2
  • 25
  • 41