Например.
Кнопки A и B управляются кнопками C и D.
Если бы я нажал C, то A было бы назначено «Pic1», а B «Pic2»
а если бы я нужно было нажать кнопку D, тогда А будет назначено «Pic3», а B «Pic4».
Если бы я затем снова нажал C, A было бы присвоено «Pic1», а B «Pic2».
Я уже пытался закодировать кнопку явно так:
Код: Выделить всё
def my_command(value):
print (value)
return
button= Button(win, image=tes[0],command= lambda: my_command(1),borderwidth=0)
button.grid(row=0,column=0)
button= Button(win, image=tes[1],command= lambda: my_command(2),borderwidth=0)
button.grid(row=0,column=1)
Код: Выделить всё
This one works fine pressed 1 my_command(1) returns Button:1 if pressed 2 my_command(2) returns Button:2) Код: Выделить всё
j=0
for i in f1:
# file up a list of pic from files, f1 is a list of valid file names
click_btn1= PhotoImage(file=i)
tes.append(click_btn1)
#set the image of the button
img_label= Label(image=tes[j])
# assign button and command
button= Button(win, image=tes[j],command= lambda j=j:
my_command(j),borderwidth=0)
button.grid(row=0,column=j)
j +=1
каждый раз, независимо от того, какая кнопка нажата (1 или 2)< /п>
Подробнее здесь: https://stackoverflow.com/questions/792 ... er-buttons
Мобильная версия