import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk color_dialog = Gtk.ColorChooserDialog(title="Pick a Color") response = color_dialog.run() if response == Gtk.ResponseType.OK: color = color_dialog.get_rgba() print("Selected color:", color.to_string()) color_dialog.destroy()
import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk def on_color_set(widget): color = widget.get_rgba() print("Selected color:", color.to_string()) color_button = Gtk.ColorButton() color_button.connect("color-set", on_color_set) window = Gtk.Window() window.add(color_button) window.show_all() Gtk.main()This code creates a color button widget. When the user clicks the button, a color chooser dialog box opens. When the user selects a color and clicks the "OK" button, the app prints the selected color in RGBA format. In conclusion, the Gtk ColorChooserDialog is provided by the Python package library `gi.repository` and it creates a dialog box which allows users to pick a color from a color palette. By using this widget, programmers can create applications with a color picker feature easily.