Python Forum
RGB() <> colorchooser.askcolor
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
RGB() <> colorchooser.askcolor
#1
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.

# -*- 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()
Reply


Messages In This Thread
RGB() <> colorchooser.askcolor - by KennethHobson - Aug-24-2022, 04:20 PM
RE: RGB() <> colorchooser.askcolor - by Yoriz - Aug-24-2022, 04:41 PM
RE: RGB() <> colorchooser.askcolor - by Gribouillis - Aug-24-2022, 05:05 PM
RE: RGB() <> colorchooser.askcolor - by deanhystad - Aug-24-2022, 05:17 PM
RE: RGB() <> colorchooser.askcolor - by deanhystad - Aug-24-2022, 05:37 PM
RE: RGB() <> colorchooser.askcolor - by woooee - Aug-24-2022, 06:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Open tkinter colorchooser at toplevel (so I can select/focus on either window) tabreturn 4 2,184 Jul-06-2022, 01:03 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020