class iFrame(wx.Frame):
def __init__(blah blah blah):
wx.Frame.__init.__(blah blah blah)
self.panel = wx.Panel(self, -1)
self.panel.SetBackgroundColour((I put a random RGB here for test purposes))
c_color = wx.Button(self.panel, -1, 'Press To Change Color')
c_color.Bind(wx.EVT_BUTTON, self.OnCC)
def OnCC(self, evt):
dlg = wx.ColourDialog().SetChooseFull(1)
if dlg.ShowModal() == wx.ID_OK:
data = dlg.GetColourData()
color = data.Colour
print (color) # I did this just to test it was returning a RGB
self.panel.SetBackgroundColour(color)
dlg.Destroy()
我尝试做的是将按钮链接到颜色对话框,将 RGB 存储在变量中并使用它来设置面板的背景颜色...我已经测试了几乎所有这些,我已经插入返回的 RGB 直接进入 self.panel 本身并且它可以工作,那么为什么当我在此方法中使用它时它不起作用
最佳答案
行dlg = wx.ColourDialog().SetChooseFull(1)
似乎是一个错误 - 不是SetChooseFull
在wx.ColourData上的方法
?
我做了一些更改以使其正常工作,并对代码进行了注释以进行说明:
def OnCC(self, evt):
data = wx.ColourData()
data.SetChooseFull(True)
# set the first custom color (index 0)
data.SetCustomColour(0, (255, 170, 128))
# set indexes 1-N here if you like.
# set the default color in the chooser
data.SetColour(wx.Colour(128, 255, 170))
# construct the chooser
dlg = wx.ColourDialog(self, data)
if dlg.ShowModal() == wx.ID_OK:
# set the panel background color
color = dlg.GetColourData().Colour
self.panel.SetBackgroundColour(color)
dlg.Destroy()
data.SetCustomColor(index, color)
填充对话框中的 N
个自定义颜色。我在下面的索引 0
处圈出了一个:
关于python - 为什么这不起作用(wxpython/颜色对话框),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6210032/