About Lesson
In this TKinter Tutorial we are going to learn about TKinter ColorChooser, so using ColoChooser you can chose a color that you want.
This is the complete code for this lesson.
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 |
import tkinter as tk from tkinter import colorchooser from tkinter import ttk class Window(tk.Tk): def __init__(self): super(Window, self).__init__() self.title("TKinter Color Chooser") self.minsize(500,400) self.wm_iconbitmap("myicon.ico") self.create_button() def create_button(self): btn = ttk.Button(self, text = "Open Color Chooser", command = self.color_chooser) btn.grid(column = 0, row = 0) def color_chooser(self): (rgbx, hx) = colorchooser.askcolor() window = Window() window.mainloop() |
This is our button and we have connected this button with the color_chooser() method.
1 2 3 |
btn = ttk.Button(self, text = "Open Color Chooser", command = self.color_chooser) btn.grid(column = 0, row = 0) |
And this is our method, basically it create a color dialog for us.
1 2 |
def color_chooser(self): (rgbx, hx) = colorchooser.askcolor() |
Run the complete code and this is the result.