坤家军纪缘 2022-10-05 23:38 采纳率: 0%
浏览 8

关于wxPython

img

img

img


我是在wxPython官网去看的,然后自己照着敲,敲下来就报错了,有没有会的呀,帮帮我

  • 写回答

2条回答 默认 最新

  • 凯歌响起 2022-10-05 23:57
    关注

    直接复制没有什么问题,你这边可以检查下自己wxpython的版本
    下面贴上我直接复制的内容

    import wx
    import wx.lib.colourdb
    
    class MyFrame(wx.Frame):
        def __init__(self, parent, title):
            wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(400, 300))
            # show the selected colour in this panel
            self.panel = wx.Panel(self)
    
            wx.lib.colourdb.updateColourDB()
            # create a colour list from the colourdb database
            colour_list = wx.lib.colourdb.getColourList()
    
            # create a choice widget
            self.choice = wx.Choice(self.panel, -1, choices=colour_list)
            # select item 0 (first item) in choice list to show
            self.choice.SetSelection(0)
            # set the current frame colour to the choice
            self.SetBackgroundColour(self.choice.GetStringSelection())
            # bind the checkbox events to an action
            self.choice.Bind(wx.EVT_CHOICE, self.OnChoice)
    
    
        def OnChoice(self, event):
            bgcolour = self.choice.GetStringSelection()
            # change colour of the panel to the selected colour ...
            self.panel.SetBackgroundColour(bgcolour)
            self.panel.Refresh()
            # show the selected colour in the frame title
            self.SetTitle(bgcolour.lower())
    
    app = wx.App()
    frame = MyFrame(None, 'Green')
    frame.Show()
    app.MainLoop()
    
    
    评论

报告相同问题?

问题事件

  • 创建了问题 10月5日