Хочу чтобы при нажатии кнопки проверялось есть ли соседние пустые(т.е самому задать данное условие)
Можно задать логические переменные на проверку
При нажатии на кнопку вызывается функция,это прописал в самой кнопке(command:
btn1 = Button(root, text=1,width=15, height=7, bg="red",fg="blue",activebackground="#2C28FF",borderwidth=3,highlightbackground="#6EFFE7",relief=SUNKEN,command=button_clicked).grid(row=0,column=0)
Не могу понять как определить какая кнопка нажата,как это сделать? Перерыл всю литературу,помогите советом.
вот код:
# -*- coding: utf-8 -*- from Tkinter import * root = Tk() root.minsize(width=500,height=500) root.maxsize(width=500,height=500) #canv = Canvas(root,width=500,height=500,bg="#92AFE2", # cursor="pencil") # command= """Функция или метод при нажатии кнопки""" #textvariable= #Связывает Tkinter переменной (обычно StringVar) к кнопке. Если переменная изменяется, кнопка текст обновляется. (textVariable/переменная) #state=The button state: NORMAL, ACTIVE or DISABLED. Default is NORMAL. (state/State) def button_clicked(): btn1['text']=5 #проверка,но не работает,если просто print 1 то сработает btn1 = Button(root, text=1,width=15, height=7, bg="red",fg="blue",activebackground="#2C28FF",borderwidth=3,highlightbackground="#6EFFE7",relief=SUNKEN,command=button_clicked).grid(row=0,column=0) #btn.grid(row=0. column=1. sticky=W) btn2 = Button(root, text=2, width=15,height=7, bg="red",fg="blue",activebackground="#2C28FF",borderwidth=3,highlightbackground="#6EFFE7",relief=SUNKEN).grid(row=0,column=1) btn3 = Button(root, text=3, width=15,height=7, bg="red",fg="blue",activebackground="#2C28FF",borderwidth=3,highlightbackground="#6EFFE7",relief=SUNKEN).grid(row=0,column=2) btn4 = Button(root, text=4, width=15,height=7, bg="red",fg="blue",activebackground="#2C28FF",borderwidth=3,highlightbackground="#6EFFE7",relief=SUNKEN).grid(row=0,column=3) btn5 = Button(root, text=5, width=15,height=7, bg="red",fg="blue",activebackground="#2C28FF",borderwidth=3,highlightbackground="#6EFFE7",relief=SUNKEN).grid(row=1,column=0) btn6 = Button(root, text=6, width=15,height=7, bg="red",fg="blue",activebackground="#2C28FF",borderwidth=3,highlightbackground="#6EFFE7",relief=SUNKEN).grid(row=1,column=1) btn7 = Button(root, text=7, width=15,height=7, bg="red",fg="blue",activebackground="#2C28FF",borderwidth=3,highlightbackground="#6EFFE7",relief=SUNKEN).grid(row=1,column=2) btn8 = Button(root, text=8, width=15,height=7, bg="red",fg="blue",activebackground="#2C28FF",borderwidth=3,highlightbackground="#6EFFE7",relief=SUNKEN).grid(row=1,column=3) btn9 = Button(root, text=9, width=15,height=7, bg="red",fg="blue",activebackground="#2C28FF",borderwidth=3,highlightbackground="#6EFFE7",relief=SUNKEN).grid(row=2,column=0) btn10 = Button(root, text=10, width=15,height=7, bg="red",fg="blue",activebackground="#2C28FF",borderwidth=3,highlightbackground="#6EFFE7",relief=SUNKEN).grid(row=2,column=1) btn11 = Button(root, text=11, width=15,height=7, bg="red",fg="blue",activebackground="#2C28FF",borderwidth=3,highlightbackground="#6EFFE7",relief=SUNKEN).grid(row=2,column=2) btn12 = Button(root, text=12, width=15,height=7, bg="red",fg="blue",activebackground="#2C28FF",borderwidth=3,highlightbackground="#6EFFE7",relief=SUNKEN).grid(row=2,column=3) btn13 = Button(root, text=13, width=15,height=7, bg="red",fg="blue",activebackground="#2C28FF",borderwidth=3,highlightbackground="#6EFFE7",relief=SUNKEN).grid(row=3,column=0) btn14 = Button(root, text=14, width=15,height=7, bg="red",fg="blue",activebackground="#2C28FF",borderwidth=3,highlightbackground="#6EFFE7",relief=SUNKEN).grid(row=3,column=1) btn15 = Button(root, text=15, width=15,height=7, bg="red",fg="blue",activebackground="#2C28FF",borderwidth=3,highlightbackground="#6EFFE7",relief=SUNKEN).grid(row=3,column=2) btn16 = Button(root, text="", width=15,height=7, bg="#FFAAA5",fg="blue",activebackground="#FFAAA5",borderwidth=3,highlightbackground="#FFAAA5",relief=SUNKEN,state=DISABLED).grid(row=3,column=3) arr_but=[btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btn10,btn11,btn12,btn13,btn14,btn15,btn16] #btn.bind("<Button-1>", Hello) #btn.pack() #canv.pack() #btn.pack() #btn1.pack() #(side='left') root.mainloop()
Заранее благодарен.