为什么这个不起作用(wxpython/color dialog)

2024-09-28 05:21:42 发布

您现在位置:Python中文网/ 问答频道 /正文

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插入到自面板它本身和它是有效的,那么为什么我在这个方法中使用它时它不起作用呢


Tags: testself面板datainitdefrgbframe
1条回答
网友
1楼 · 发布于 2024-09-28 05:21:42

dlg = wx.ColourDialog().SetChooseFull(1)似乎是一个bug,SetChooseFull不是{}上的方法吗?在

我做了一些更改以使其正常工作,并对代码进行了注释以说明:

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

相关问题 更多 >

    热门问题