python - 为什么这不起作用(wxpython/颜色对话框)

标签 python wxpython colordialog

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)似乎是一个错误 - 不是SetChooseFullwx.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 处圈出了一个:

enter image description here

关于python - 为什么这不起作用(wxpython/颜色对话框),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6210032/

相关文章:

python - 如果任何列包含特定值,则在所述行中删除 Pandas Dataframe 中的一行

python - Tensorflow 可视化工具 "Tensorboard"在 Anaconda 下不工作

windows-10 - 在 Windows 10 上绑定(bind)一些全局热键失败

python - Matplotlib:音频播放器光标(滑动垂直线)的动画,在 WxPython 上,位 block 传输看起来损坏

c# - Windows 窗体中的自定义颜色对话框

python - 使用 https 代理请求

python - wxPython - 禁用整个菜单

C# - 跨表单使用 ColorDialog

android - 简单的颜色选择器

python - 数据实验室 : How to export Big Query standard SQL query to dataframe?