0

When I press one of the buttons the color always applies to the last button. Could you help me. Thanks ^^

import tkinter as tk
from tkinter import ttk
from tkinter import colorchooser

tabStyle = tk.Tk()
tabStyle['background'] = "black"
texts = ['Background', 'Foreground', 'Cursor' , '...']
labels = []
buttons = []

def AskColor(c):
    color = colorchooser.askcolor()[1]
    buttons[c]['background'] = color

for c, s in enumerate(texts):
    labels.append(tk.Label(tabStyle, text=s, fg="white", bg="black"))
    buttons.append(tk.Button(tabStyle, width=5, bg="white", command=lambda : AskColor(c)))

for ((l, label), (b, button)) in zip(enumerate(labels), enumerate(buttons)):
    label.grid(column=0, row=l, sticky="W")
    button.grid(column=1, row=b, padx=2)

tabStyle.mainloop()
roganjosh
  • 12,594
  • 4
  • 29
  • 46
LousAjo
  • 21
  • 7

0 Answers0