为什么这不起作用(wxpython/颜色对话框)
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 本身并且它可以工作,那么为什么当我在此方法中使用它时它不起作用
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()
What I've tried to do was link a button to a color dialog, store the RGB in a variable and use it to set the panel's background color...I've tested almost all of this, I've inserted the returned RGB directly into the self.panel itself and it works, so why doesn't it work when I use it within this method
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
dlg = wx.ColourDialog().SetChooseFull(1)
行似乎是一个错误 - 不是SetChooseFull
上wx.ColourData
的方法>?我做了一些更改以使其正常工作,并对代码进行了注释以进行说明:
data.SetCustomColor(index, color)
填充对话框中的N
自定义颜色。我在下面的索引0
处圈出了一个:The line
dlg = wx.ColourDialog().SetChooseFull(1)
seems like a bug -- isn'tSetChooseFull
a method onwx.ColourData
?I made a few changes to get it working and commented the code to illustrate:
The
data.SetCustomColor(index, color)
populates theN
custom colors in the dialog. I've circled the one at index0
below: