Python 简单的幻灯片放映(不是我的代码)不会';行不通

Python 简单的幻灯片放映(不是我的代码)不会';行不通,python,wxpython,Python,Wxpython,这段代码来自python论坛,在那里可以通过简单的幻灯片查看图像。我认为它不起作用,因为它创建了图像,但没有在屏幕上显示它们。我想我可能需要实现某种回调,但这是解决问题的正确方法吗?如果我去掉while循环,只使用for,它将只显示一个图像,而不显示其余的图像 class SecondFrame(wx.Frame): def __init__(self, parent, mysize): gets correct path for images from working

这段代码来自python论坛,在那里可以通过简单的幻灯片查看图像。我认为它不起作用,因为它创建了图像,但没有在屏幕上显示它们。我想我可能需要实现某种回调,但这是解决问题的正确方法吗?如果我去掉while循环,只使用for,它将只显示一个图像,而不显示其余的图像

class SecondFrame(wx.Frame):
    def __init__(self, parent, mysize):
        gets correct path for images from working directory
        wx.EVT_PAINT(self, self.onPaint)

    def onPaint(self, event=None):
        dc = wx.PaintDC(self)
        while self.loops > 0:
            self.loops -= 1
            for self.ix, bmp in enumerate(self.image_list):     
                w, h = bmp.GetSize()
                info = "Graphs"
                self.SetTitle(info)
                dc.DrawBitmap(bmp, 10, 10, True)
                wx.MilliSleep(self.delay)
                if self.delay > 200:
                    dc.Clear()

我不确定你是从哪里得到这些代码的,但就目前的情况来看,它是不完整的,不可运行的,而且总体上编码非常糟糕(IMHO)。请尝试此代码段(未测试):

类第二帧(wx.Frame):
定义初始化(自、父、mysize):
#随便这里
self.timer=wx.timer(self,wx.ID\u ANY)
self.SetTitle(“图形”)
self.Bind(wx.EVT_-PAINT,self.OnPaint)
self.Bind(wx.EVT_擦除_背景,self.OnErase)
self.Bind(wx.EVT_TIMER,self.OnTimer)
自定时器启动(自延时)
def OnPaint(自身、事件):
dc=wx.BufferedPaintDC(自)
dc.SetBackground(wx.Brush(self.getbackgroundcolor()))
dc.Clear()

如果self.loops,我们就不会找出为什么有些东西不适合你。你需要找出它不起作用的原因,然后询问你应该做些什么来修复那个/那个些特定的错误你得到了什么特定的错误?我知道为什么它不起作用,但我需要知道我可以用什么来修复它。我不是要你给我工作代码。我没有得到任何错误,但它只是没有显示任何东西。我注释掉了while循环,刚刚使用了for ix,bmp…和dc.DrawBitmap,它显示了第一个图像。kevin的意思是,您的示例需要简短且独立。阅读:
class SecondFrame(wx.Frame):

    def __init__(self, parent, mysize):

        # Whatever here

        self.timer = wx.Timer(self, wx.ID_ANY)

        self.SetTitle("Graphs")

        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnErase)
        self.Bind(wx.EVT_TIMER, self.OnTimer)

        self.timer.Start(self.delay)


    def OnPaint(self, event):

        dc = wx.BufferedPaintDC(self)
        dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
        dc.Clear()

        if self.loops <= 0:
            return

        bmp = self.image_list[self.loops]        
        w, h = bmp.GetSize()

        dc.DrawBitmap(bmp, 10, 10, True)
        wx.MilliSleep(self.delay)


    def OnErase(self, event):

        pass


    def OnTimer(self, event):

        self.loops -= 1
        if self.loops <= 0:
            return

        self.Refresh()