Например.
Кнопка A и кнопка B управляются кнопками C и D.
Если я нажму C, то A будет «Pic1», а B — «Pic2»,
и если я нажму кнопку D тогда A — это «Pic3», а B — это «Pic4»
а также обратно к A — «Pic1», а B — «Pic2», если я снова нажму кнопку C.
Я уже пытался явно закодировать кнопку следующим образом. :
Код: Выделить всё
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
Мобильная версия