T
T
Timur2014-08-30 17:58:15
Python
Timur, 2014-08-30 17:58:15

How to extract color in Hex (#000000) format from wxPython ColourDialog?

Hello,
I'm writing a Python 2.7 program using wxPython for the GUI and matplotlib for plotting. It was decided to use wx.ColourDialog to set the chart color. 84a6c9fb6e664959a20ad7021228e323.png
How can I get exactly the hex code from this dialog?
The code below returns an RGB value with values ​​from 0 to 255, for example (128, 0, 128)

def onColorDlg(self, event):
        dlg = wx.ColourDialog(self)
 
        dlg.GetColourData().SetChooseFull(True)
 
        if dlg.ShowModal() == wx.ID_OK:
            data = dlg.GetColourData()
            print 'You selected: %s\n' % str(data.GetColour().Get())
 
        dlg.Destroy()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Timur, 2014-08-30
@murych

Found a solution

dlg.GetColourData().SetChooseFull(True)
 
        if dlg.ShowModal() == wx.ID_OK:
            data = dlg.GetColourData()
            color = data.GetColour() 
            colorHexStr = "#%02x%02x%02x" % color.Get() 
            print(colorHexStr)
 
        dlg.Destroy()

P
Pavel, 2014-08-30
@VoRez

Convert from decimal to hexadecimal.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question