wxPython-创建向导,具有更改工具';下一个';基于用户选择的页面

wxPython-创建向导,具有更改工具';下一个';基于用户选择的页面,python,wxpython,Python,Wxpython,我正在尝试使用wxWizard类创建一个简单的安装程序。在第一页(第0页),我想有3个选项 1. Install (click Next goes to page install1) 2. Upgrade (click Next goes to page upgrade1) 3. Remove (click Next goes to page remove1) 由于我缺乏面向对象编程(以及一般编程)的经验,我无法理解如何创建能够实现这一点的page0对象 如果在install1之前创建

我正在尝试使用wxWizard类创建一个简单的安装程序。在第一页(第0页),我想有3个选项

 1. Install (click Next goes to page install1) 
 2. Upgrade (click Next goes to page upgrade1)
 3. Remove (click Next goes to page remove1)
由于我缺乏面向对象编程(以及一般编程)的经验,我无法理解如何创建能够实现这一点的page0对象

如果在install1之前创建页面0:未定义全局名称“install1” 如果在第0页之前创建install1:超过最大递归深度 如果我看一下SkipNextPage类:有一个时髦的
GetNext()
方法也不明白

请帮忙

import wx
import wx.wizard

class InstallPage_Dyn(wx.wizard.PyWizardPage):
    def __init__(self, parent, title):
        wx.wizard.PyWizardPage.__init__(self, parent)
        self.next = self.prev = None


class InstallPage0(wx.wizard.PyWizardPage):
    def __init__(self, parent, title):
        wx.wizard.PyWizardPage.__init__(self, parent)
        self.next = self.prev = None
        self.box = wx.RadioBox (self, -1, 'Choose one of the options below and hit Next\n', choices=['Install','Upgrade','Remove'], style = wx.VERTICAL | wx.EXPAND)

        # Set Next button based on user choice
        self.box.Bind(wx.EVT_RADIOBOX, self.SetNext(install1))

    # Setter and getter methods to specify Next and Previous buttons#     
    def SetNext(self, next):
        userchoice = self.box.GetSelection()
        if userchoice == 0: 
            self.SetNext(install1)
        elif userchoice == 1:
            self.SetNext(upgrade1)
        elif userchoice == 2:
            self.SetNext(remove1)

    def SetPrev(self, prev):
        return self.prev

    def GetNext(self):
        return self.next

    def GetPrev(self):
        return self.prev


# Define application and create the wizard
app = wx.App()

wizard = wx.wizard.Wizard(None, -1, "Installer")
wizard.SetPageSize((500,350))

# User selected install. Create the pages
install1 = InstallPage_Dyn(wizard, "Install")
upgrade1 = InstallPage_Dyn(wizard, "Upgrade")
remove1 = InstallPage_Dyn(wizard, "Remove")

# Create page instances
page0 = InstallPage0(wizard, "Installer")

wizard.RunWizard(page0)
试试这个

class InstallPage_Dyn(wx.wizard.PyWizardPage):
    def __init__(self, parent, title):
        wx.wizard.PyWizardPage.__init__(self, parent)
        self.title = wx.StaticText(self,-1,title)
        self.title.SetFont(wx.Font(40,wx.FONTFAMILY_DEFAULT,wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_BOLD))
        self.next = self.prev = None
    def SetPrev(self,prev):
        self.prev = prev
    def GetPrev(self):
        return self.prev

class InstallPage0(wx.wizard.PyWizardPage):
    def __init__(self, parent, title,optional_panels = {}):
        wx.wizard.PyWizardPage.__init__(self, parent)
        self.prev = self
        self.next = optional_panels.values()[0]
        self.box = wx.RadioBox (self, -1, 'Choose one of the options below and hit Next\n', choices=optional_panels.keys(), style = wx.VERTICAL | wx.EXPAND)
        self.opts = optional_panels.keys()
        self.pages   = optional_panels.values()
        for p in self.pages:
            p.SetPrev(self)
        self.next = self.pages[0]
        self.optional_panels = optional_panels

    def GetNext(self):
        return self.pages[self.box.GetSelection()]
    def GetPrev(self):
        return self.prev
...
page0 = InstallPage0(wizard, "Installer",{'install':install1,'upgrade':upgrade1,'remove':remove1})

wizard.RunWizard(page0)
#app.MainLoop()
这是完整的代码。。。将其命名为wiz.py并运行它

import wx
import wx.wizard

class InstallPage_Dyn(wx.wizard.PyWizardPage):
    def __init__(self, parent, title):
        wx.wizard.PyWizardPage.__init__(self, parent)
        self._title = title
        self.title = wx.StaticText(self,-1,title)
        self.title.SetFont(wx.Font(40,wx.FONTFAMILY_DEFAULT,wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_BOLD))
        self.next = self.prev = None
    def SetPrev(self,prev):
        self.prev = prev
    def GetPrev(self):
        return self.prev

class InstallPage0(wx.wizard.PyWizardPage):
    def __init__(self, parent, title,optional_panels = {}):
        wx.wizard.PyWizardPage.__init__(self, parent)
        self.prev = self
        self.next = optional_panels[0]
        options = [p._title for p in optional_panels]
        self.box = wx.RadioBox (self, -1, 'Choose one of the options below and hit Next\n', choices=options, style = wx.VERTICAL | wx.EXPAND)
        self.pages   = optional_panels
        for p in self.pages:
            p.SetPrev(self)
        self.next = install1
        self.optional_panels = optional_panels
    def SetPrev(self, prev):
        self.prev = prev
        return self.prev
    def GetNext(self):
        return self.pages[self.box.GetSelection()]
    def GetPrev(self):
        return self.prev


# Define application and create the wizard
app = wx.App(redirect=False)

wizard = wx.wizard.Wizard(None, -1, "Installer")
wizard.SetPageSize((500,350))

# User selected install. Create the pages
install1 = InstallPage_Dyn(wizard, "Install")
upgrade1 = InstallPage_Dyn(wizard, "Upgrade")
remove1 = InstallPage_Dyn(wizard, "Remove")

# Create page instances
page0 = InstallPage0(wizard, "Installer",[install1,upgrade1,remove1])

wizard.RunWizard(page0)

谢谢乔兰。不幸的是,这对我不起作用。Page0将打开,但显示的不是“下一步”按钮,而是“完成”按钮。几乎就好像第0页。下一页从未设置。你是什么意思?。。。它应该是好的,我刚刚发布了我的文件中的原始代码,对我来说运行良好…你得到了什么错误?好的,很好,你的完整代码清单工作得很好。我试图将你的代码插入到我的原始脚本中,一定是弄错了。既然你在这上面花了这么多时间,我可以请你澄清一下:为什么self.next=optional_panels.values()[0]在你的代码中基本上是对install1的引用,而当我直接使用self.next=install1时它进入无限递归?我不这么认为。。。如果我将
self.next=self.pages[0]
更改为
self.next=install1
同样有效,非常感谢您的帮助。我会尽力找出是什么把我甩了。