# ========================================================= # Generate a chart of named colors # ========================================================= # From: https://pastebin.com/fhaDYRW0 # ========================================================= import tkinter as tk from tk_color_names import COLORS # --------------------------------------------------------- # global variables # --------------------------------------------------------- MAX_ROWS = 30 FONT_SIZE = 10 # --------------------------------------------------------- # function - build color chart # --------------------------------------------------------- def ColorChart(root): f = tk.Frame(root) r = 0 # row count c = 0 # column count cc = 0 # color count # --- for each color, create a lable for color in COLORS: label = tk.Label(f,text=color, bg=color, font=("Times", FONT_SIZE, "bold")) label.grid(row=r, column=c, sticky="ew") r += 1 cc += 1 if r > MAX_ROWS: r = 0 c += 1 f.grid(row=0, column=0) return cc # --------------------------------------------------------- # main # --------------------------------------------------------- if __name__ == '__main__': root = tk.Tk() root.title("Named Color Chart") cc = ColorChart(root) print('{} colors in chart'.format(cc)) root.mainloop()