Gtk.ColorButton
Gtk.ColorButton — A button to launch a color selection dialog
Object Hierarchy:
GObject
╰── GInitiallyUnowned
╰── Gtk.Widget
╰── Gtk.Container
╰── Gtk.Bin
╰── Gtk.Button
╰── Gtk.ColorButton
See also:
GtkColorSelectionDialog, Gtk.FontButton
Functions:
- new
() -> Gtk.Widget
- new_with_color
(color:Gdk.Color) -> Gtk.Widget
- new_with_rgba
(rgba:Gdk.RGBA) -> Gtk.Widget
- set_color
(self, color:Gdk.Color)
- get_color
(self) -> color:Gdk.Color
- set_alpha
(self, alpha:int)
- get_alpha
(self) -> int
- set_rgba
(self, color:Gdk.RGBA)
- get_rgba
(self) -> color:Gdk.RGBA
- set_use_alpha
(self, use_alpha:bool)
- get_use_alpha
(self) -> bool
- set_title
(self, title:str)
- get_title
(self) -> str
Description:
The Gtk.ColorButton
is a button which displays the currently selected color and allows to open a color selection dialog to change the color.
It is suitable widget for selecting a color in a preference dialog.
Function Details:
new()
new () -> Gtk.Widget
Creates a new color button. This returns a widget in the form of a small button containinga swatch representing the current selected color. When the buttonis clicked, a color-selection dialog will open, allowing the userto select a color. The swatch will be updated to reflect the newcolor when the user finishes.
Returns: a new color button
Since: 2.4
new_with_color()
new_with_color (color:Gdk.Color) -> Gtk.Widget
Gtk.ColorButton:new_with_color
has been deprecated since version 3.4 and should not be used in newly-written code.
Use Gtk.ColorButton:new_with_rgba()
instead.
Creates a new color button.
Returns: a new color button
Since: 2.4
new_with_rgba()
new_with_rgba (rgba:Gdk.RGBA) -> Gtk.Widget
Creates a new color button.
Returns: a new color button
Since: 3.0
set_color()
set_color (self, color:Gdk.Color)
Gtk.ColorButton:set_color
is deprecated and should not be used in newly-written code.
Use `Gtk.ColorChooser:set_rgba
()instead.
Sets the current color to be
color`.
- Since: 2.4
get_color()
get_color (self) -> color:Gdk.Color
Gtk.ColorButton:get_color
has been deprecated since version 3.4 and should not be used in newly-written code.
Use `Gtk.ColorChooser:get_rgba
()instead.
Sets
colorto be the current color in the
Gtk.ColorButton` widget.
- Since: 2.4
set_alpha()
set_alpha (self, alpha:int)
Gtk.ColorButton:set_alpha
has been deprecated since version 3.4 and should not be used in newly-written code.
Use `Gtk.ColorChooser:set_rgba
()instead.
Sets the current opacity to be
alpha`.
- Since: 2.4
get_alpha()
get_alpha (self) -> int
Gtk.ColorButton:get_alpha
has been deprecated since version 3.4 and should not be used in newly-written code.
Use `Gtk.ColorChooser:get_rgba
()` instead.
Returns the current alpha value.
Returns: an integer between 0 and 65535
Since: 2.4
set_rgba()
set_rgba (self, color:Gdk.RGBA)
Gtk.ColorButton:set_rgba
has been deprecated since version 3.4 and should not be used in newly-written code.
Use `Gtk.ColorChooser:set_rgba
()instead.
Sets the current color to be
rgba`.
[skip]
- Since: 3.0
get_rgba()
get_rgba (self) -> color:Gdk.RGBA
Gtk.ColorButton:get_rgba
has been deprecated since version 3.4 and should not be used in newly-written code.
Use `Gtk.ColorChooser:get_rgba
()instead.
Sets
rgbato be the current color in the
Gtk.ColorButton` widget.
[skip]
- Since: 3.0
set_use_alpha()
set_use_alpha (self, use_alpha:bool)
Gtk.ColorButton:set_use_alpha
has been deprecated since version 3.4 and should not be used in newly-written code.
Use `Gtk.ColorChooser:set_use_alpha
()` instead.
Sets whether or not the color button should use the alpha channel.
- Since: 2.4
get_use_alpha()
get_use_alpha (self) -> bool
Gtk.ColorButton:get_use_alpha
has been deprecated since version 3.4 and should not be used in newly-written code.
Use `Gtk.ColorChooser:get_use_alpha
()` instead.
Does the color selection dialog use the alpha channel ?
Returns:
True
if the color sample uses alpha channel,FALSE
if notSince: 2.4
set_title()
set_title (self, title:str)
Sets the title for the color selection dialog.
- Since: 2.4
get_title()
get_title (self) -> str
Gets the title of the color selection dialog.
Returns: An internal string, do not free the return value
Since: 2.4
Example:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class ColorButton(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.set_title('ColorButton')
self.set_default_size(200, -1)
self.connect('destroy', Gtk.main_quit)
colorbutton = Gtk.ColorButton()
colorbutton.connect('color-set', self.on_color_set)
self.add(colorbutton)
def on_color_set(self, colorbutton):
color = colorbutton.get_rgba()
red = int(color.red * 255)
green = int(color.green * 255)
blue = int(color.blue * 255)
print('Hex: #%02x%02x%02x' % (red, green, blue))
window = ColorButton()
window.show_all()
Gtk.main()