Aug-24-2022, 04:20 PM
I pick blue color but the value returned is red, not blue as you can see in the code comments. Should I parse out the RGB values from the picked color and use RBG() to get the right value for use outside of tkinter?
The value from colorchooser.askcolor is fine for setting colors for a label in tkinter.
The value from colorchooser.askcolor is fine for setting colors for a label in tkinter.
# -*- coding: utf-8 -*-
from ctypes.wintypes import RGB
from tkinter import *
from tkinter import colorchooser
color = RGB(0, 0, 255) # Blue
print(color) # 16711680 = #FF000 = Blue
print(RGB(255,0,0)) # 255 = Red
def choose_color():
# variable to store hexadecimal code of color
color_code = colorchooser.askcolor(title ="Choose color")
#rgbTuplet, colourString= colorchooser.askcolor(title ="Choose color")
print(color_code[0]) # (0, 0, 255)
print(color_code[1]) # #0000ff
print(int(color_code[1].replace('#',''), 16)) # 255, red by RGB()
root = Tk()
button = Button(root, text = "Select color",
command = choose_color)
button.pack()
root.geometry("50x50")
root.mainloop()
