Answer the question
In order to leave comments, you need to log in
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.
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
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()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question