![]() |
RGB() <> colorchooser.askcolor - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: RGB() <> colorchooser.askcolor (/thread-38034.html) |
RGB() <> colorchooser.askcolor - KennethHobson - Aug-24-2022 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() RE: RGB() <> colorchooser.askcolor - Yoriz - Aug-24-2022 On windows 10 I choose Blue and get back
RE: RGB() <> colorchooser.askcolor - KennethHobson - Aug-24-2022 Yes, I showed that in the comments. But, look at the numerical value #0000ff. RGB() shows it as: 16711680 which is #FF000. The value shown by the askcolor is #0000ff which is 255. Do you see my issue now? RE: RGB() <> colorchooser.askcolor - Gribouillis - Aug-24-2022 It is plausible that Windows' RGB() function stores the red at the least significant byte. You could define def RGB(r, g, b): return (((b << 8) | g) << 8) | r ... print(RGB(*color_code[0])) RE: RGB() <> colorchooser.askcolor - deanhystad - Aug-24-2022 Windows uses a different order than Python for colors. In Python red is 16711680 and in windows red is 255. Why do you think this matters at all? Are you trying to pass integer color values to a windows DLL? RE: RGB() <> colorchooser.askcolor - KennethHobson - Aug-24-2022 (Aug-24-2022, 05:17 PM)deanhystad Wrote: Windows uses a different order than Python for colors. In Python red is 16711680 and in windows red is 255. Why do you think this matters at all? Are you trying to pass integer color values to a windows DLL? RE: RGB() <> colorchooser.askcolor - KennethHobson - Aug-24-2022 Yes, I am passing the integer to Windows using SetWinColors. RE: RGB() <> colorchooser.askcolor - deanhystad - Aug-24-2022 Then you will want to get the individual red, green, blue components of the color and use them with the windows RGB color macro. This is the recommendation when using SetSysColors (winuser.h). You do not want to send the Python color directly. 32 bit color values are meaningless without context. Just like 32bit integer values, or floats, or any multi-byte data. RE: RGB() <> colorchooser.askcolor - KennethHobson - Aug-24-2022 Thanks, I just found it odd. This closes my question. I can achieve my goal by using RBG() with: r, g, b = color_code[0] RE: RGB() <> colorchooser.askcolor - woooee - Aug-24-2022 FYI, see any differences here color = RGB(0, 0, 255) # Blue print(RGB(255,0,0)) # 255 = Red |