How to call a function?

Help! Learn Tkinter and Canvas. The essence of the code: when you click on one image, it is replaced by another. Everything works, but as soon as I decided to make it so that when you click on the second picture, which replaced the first, again appeared first (like cycle) are faced with the problem:

c.tag_bind(imag1, 'Button-1', p2) - this line can't call a function without arguments, i.e., p2() , it calls it only if you use p2(event) is a matter known.

To make the script work I need in this case to call the function p1() before the root.mainloop(), and if I call the "def p1():" via "p1()" - function is called, but then gives an error when the c design.tag_bind(imag2, 'Button-1', p1) trying to call the function p1() again (she can't; the reason described above)

And the main bottleneck is that if I call the function "def p1(event)" through "p1(event)" gives an error (NameError: name 'event' is not defined)

How to call a function in this case how to run the script? Or how to declare the "event" because in my script it is only used as costs features call via bind?

And Yes "command=p1" would solve this issue but it's not a button here, it doesn't work, maybe there are analogues?

p.s. "Yes, talent to explain poponyatnee deprived)"

root = Tk()
root.title("LH")

c = Canvas(root, width=500, height=500)
c.pack()


def p1(event): #or def p1():
 image1 = Image.open("C://...1.png")
 photo1 = ImageTk.PhotoImage(image1) 
 c.image = photo1
 imag1 = c.create_image(200, 250, image=photo1)

 c.tag_bind(imag1, '<Button-1>', p2)

 def p2(event):
 image2 = Image.open("C://...2.png") 
 photo2 = ImageTk.PhotoImage(image2) 
 c.image = photo2
 imag2 = c.create_image(200, 250, image=photo2)

 c.tag_bind(imag2, '<Button-1>', p1)

p1() #or p1(event)
root.mainloop()
April 4th 20 at 00:57
1 answer
April 4th 20 at 00:59
Solution
In short sorry for the stupid question! Maybe it's not right, but I just asked a value for the variable event.
If there are more elegant and intelligent solutions that please throw a message=)

# -*- coding: utf8 -*-
from tkinter import *
import tkinter.ttk as ttk
from PIL import Image, ImageTk 

root = Tk()
root.title("LH")

c = Canvas(root, width=500, height=500)
c.pack()

event = 123
imag1 = 0
imag2 = 0

def p1(event):
c.delete(imag2)
 image1 = Image.open("C://1.png")
 photo1 = ImageTk.PhotoImage(image1) 
 c.image = photo1
 imag1 = c.create_image(200, 250, image=photo1) 
 c.tag_bind(imag1, '<Button-1>', p2)


def p2(event):
c.delete(imag1)
 image2 = Image.open("C://2.png") 
 photo2 = ImageTk.PhotoImage(image2) 
 c.image = photo2 
 imag2 = c.create_image(200, 250, image=photo2) 
 c.tag_bind(imag2, '<Button-1>', p1)

p1(event)
root.mainloop()

Find more questions by tags Python