1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| import tkinter as tk
class Appli1(tk.Tk):
__lettres = "ABCD"
def __init__(self):
super().__init__()
self.__creer_widgets()
def __creer_widgets(self):
self.grid()
self.bout = dict(
(
lettre,
tk.Button(
self,
text=lettre,
width="10",
height="10",
command=lambda i=lettre: self.imprime_lettre(i),
),
) for lettre in Appli1.__lettres
)
for (i, lettre) in enumerate(self.__lettres, 1):
self.bout[lettre].grid(row=1, column=i)
def imprime_lettre(self, lettre): print(lettre)
def change_couleur(self,bouton):
for (i, lettre) in enumerate(self.__lettres, 1):
if lettre == bouton:
self.bout[lettre].configure(bg="yellow")
if __name__ == "__main__":
app = Appli1()
app.change_couleur('B')
app.mainloop() |
Partager