Following program changes window colors using colorchooser module.
User clicks the button that created by tkinter module on GUI. Than user selects a color with the colorpicker and change the background color.
Tkinter Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | import tkinter as tk from tkinter.colorchooser import * def getColor(): color = askcolor() print(color[1]) mw.configure(background=color[1]) mw = tk.Tk() mw.title('COLOR ME!!!') mw.geometry("500x500") mw.resizable(0, 0) tk.Button(text='Select Color', command=getColor).pack() mw.mainloop() |
colorchooser module allows us to choose color with askcolor() method that returns the color code an array value.
The color value will look like follows:
1 2 3 | ((0.0, 0.0, 255.99609375), '#0000ff') |
color[0]: returns rba codes
color[1] returns hex codes
Output: