Python Forum
GTK3.0 Color Selection Widget
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GTK3.0 Color Selection Widget
#1
Hello.
I hope this is the right place to ask and someone can help me with GTK+ 3.0 Color Selection Widget,
It works fine and i can get color and alpha values, but how do i get HSV values?

I've been all over dokumentation and spend a half night to figure it out.
Is it not possible even as the values are showed in the widget?

In advance: thank you

Robib.
Reply
#2
It doesn't look like GTK+ Color chooser has an HSV mode, see: https://athenajc.gitbooks.io/python-gtk-...ooser.html

However, you should be able to use python's colorsys ( https://docs.python.org/3/library/colorsys.html )
to convert from get_rgba to HSV specific documentation here
Robib likes this post
Reply
#3
Okay.
I just wanted to be sure that i didn't missed something.
Reply
#4
A simple example, doubleclick the color

#!/usr/bin/python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class ColorChooserWidget(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_title('ColorChooserWidget')
        self.set_icon_name("preferences-color")
        self.set_border_width(5)
        self.connect('destroy', Gtk.main_quit)

        self.colorchooserwidget = Gtk.ColorChooserWidget(show_editor=False)
        self.add(self.colorchooserwidget)
        self.color = self.colorchooserwidget.get_rgba()
        self.colorchooserwidget.connect('color-activated', self.on_color_activated)        

    def on_color_activated(self, colorchooserwidget, color):
        r = int(color.red * 255)
        g = int(color.green * 255)
        b = int(color.blue * 255)
        rgb_color = f"RGB ({r}, {g}, {b})"
        print(rgb_color)
        hex_color = f"#{self.rgb2hex(r, g, b)}"
        print(hex_color)
        self.set_title(f"{rgb_color}  {hex_color}")
        
    def rgb2hex(self, r, g, b):
        def rgb(c):
            if c < 0: return 0
            if c > 255 : return 255
            return c
            
        r = rgb(r)
        g = rgb(g)
        b = rgb(b)
         
        val = "%02x%02x%02x" % (r, g, b)
        return(val.upper())
        

window = ColorChooserWidget()
window.show_all()

Gtk.main()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [GI] Error when I close the interface Glade/GTK3/ Charles25 2 2,115 Jun-16-2020, 07:02 PM
Last Post: Charles25
  Restoring Tkinter widget background to original color pythonprogrammer 1 2,913 Dec-16-2019, 04:59 AM
Last Post: woooee
  Problem with Gtk3 and GLArea gsohler 0 2,167 Aug-12-2019, 07:33 AM
Last Post: gsohler
  Help - GTK3 + Pango: Printing data as table format scandido 0 3,168 Jan-26-2018, 06:03 PM
Last Post: scandido
  python3 + gtk3 image sequence changos 0 3,271 Apr-24-2017, 04:10 PM
Last Post: changos
  Python minesweeper game gtk3 get label value after click lukassz 0 3,233 Mar-25-2017, 08:14 PM
Last Post: lukassz

Forum Jump:

User Panel Messages

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