2 saohddz saohddz 于 2014.05.04 17:16 提问

在wxpython中加了按钮,也绑定到了单击的回调函数,但不能正确的回调

main2.py

-*- coding: utf-8 -*-

import wx
import wx.wizard as wiz
import p1
import p2
import p3
import p4
import p5

class MyApp(wx.App):
def init(self):
wx.App.__init__(self)
self.appWizard = wiz.Wizard(None, -1, "大都市动态更新向导".decode('utf-8'))
self.pageCount = 5
self.InitPages()
self.setPagesLink()
self.runWizard()

def InitPages(self):
    self.pagesList = list()
    self.pageFactory = PageFactory()
    for p in "p1,p2,p3,p4,p5".split(","):
        self.pagesList.append(self.pageFactory.createPages(p,self.appWizard))

def setPagesLink(self):
    for i in range(self.pageCount):
        if 0 < i < self.pageCount:
            self.pagesList[i-1].SetNext(self.pagesList[i])
            self.pagesList[i].SetPrev(self.pagesList[i-1])

def runWizard(self):
    self.appWizard.FitToPage(self.pagesList[0])
    self.appWizard.RunWizard(self.pagesList[0])
    self.appWizard.Destroy()

class PageFactory():
def createPages(self,pageStr,appWizard):
if pageStr == "p1":
return p1.p1(appWizard)
elif pageStr == "p2":
return p2.p2(appWizard)
elif pageStr == "p3":
return p3.p3(appWizard)
elif pageStr == "p4":
return p4.p4(appWizard)
elif pageStr == "p5":
return p5.p5(appWizard)

if name == "__main__":
app = MyApp()
app.MainLoop()


p1.py

-*- coding: utf-8 -*-

import wx
import wx.wizard as wiz
import wx.lib.filebrowsebutton as filebrowse
import os
import sys

class p1(wiz.WizardPageSimple):
configUrl = ""
logUrl = ""
def init(self,appWizard):
wiz.WizardPageSimple.__init__(self, appWizard)
self.initViews();

def initViews(self):
    #页标题和分界线
    self.pageTitle = wx.StaticText(self,label="设置 Config.ini 和 Log.txt 路径".decode('utf-8'))
    self.staline = wx.StaticLine(self)

    #提示字,输入框1,两个按钮
    self.confFileUrl = wx.StaticText(self,label="请输入Config.ini的路径".decode('utf-8'))
    self.fbbh = filebrowse.FileBrowseButtonWithHistory(self,size=(450,-1),changeCallback = self.fbbhCallback)            
    self.fbbh.callCallback = False
    self.fbbh.SetHistory(["this is history"])
    self.fbbhEBtn = wx.Button(self,-1,"打开文件".decode('utf-8'))
    self.fbbhDBtn = wx.Button(self,-1,"显示".decode('utf-8'))
    self.Bind(wx.EVT_BUTTON, self.OnClickEbtn1, self.fbbhEBtn)
    self.Bind(wx.EVT_BUTTON, self.OnClickDbtn1, self.fbbhDBtn)

    #提示字,输入框2,两个按钮
    self.logFileUrl = wx.StaticText(self,label="请输入Log.txt的路径".decode('utf-8'))
    self.fbbh2 = filebrowse.FileBrowseButtonWithHistory(self,size=(450,-1),changeCallback = self.fbbhCallback2)            
    self.fbbh2.callCallback = False
    self.fbbh2.SetHistory(["this is history"])
    self.fbbhEBtn2 = wx.Button(self,-1,"打开文件".decode('utf-8'))
    self.fbbhDBtn2 = wx.Button(self,-1,"显示".decode('utf-8'))
    self.Bind(wx.EVT_BUTTON, self.OnClickEbtn2, self.fbbhEBtn)
    self.Bind(wx.EVT_BUTTON, self.OnClickDbtn2, self.fbbhDBtn)

    #Sizer布局
    mainSizer = wx.BoxSizer(wx.VERTICAL)
    topSizer = wx.BoxSizer(wx.VERTICAL)
    midSizer = wx.BoxSizer(wx.VERTICAL)
    mid2Sizer = wx.BoxSizer(wx.HORIZONTAL)
    mid3Sizer = wx.BoxSizer(wx.HORIZONTAL)

    topSizer.Add(self.pageTitle,flag=wx.ALIGN_CENTER_HORIZONTAL|wx.BOTTOM,border=10)
    topSizer.Add(wx.StaticLine(self),flag=wx.GROW)
    mainSizer.Add(topSizer,flag=wx.EXPAND)

    midSizer.Add(self.confFileUrl)
    midSizer.Add(self.fbbh)
    mid2Sizer.Add(self.fbbhEBtn,flag=wx.RIGHT,border=10)
    mid2Sizer.Add(self.fbbhDBtn)
    midSizer.Add(mid2Sizer,flag=wx.BOTTOM|wx.CENTER,border=20)
    midSizer.Add(self.logFileUrl)
    midSizer.Add(self.fbbh2)
    mid3Sizer.Add(self.fbbhEBtn2,flag=wx.RIGHT,border=10)
    mid3Sizer.Add(self.fbbhDBtn2)
    midSizer.Add(mid3Sizer,flag=wx.CENTER,border=20)
    mainSizer.Add(midSizer,flag=wx.EXPAND|wx.TOP,border=10)

    self.SetSizer(mainSizer)

def fbbhCallback(self, evt):
    if hasattr(self, 'fbbh'):
        value = evt.GetString()
        if not value:
            return
        print value
        self.configUrl = value
        history = self.fbbh.GetHistory()
        if value not in history:
            history.append(value)
            self.fbbh.SetHistory(history)
            self.fbbh.GetHistoryControl().SetStringSelection(value)

def fbbhCallback2(self, evt):
    if hasattr(self, 'fbbh2'):
        value = evt.GetString()
        if not value:
            return
        print value
        self.logUrl = value
        history = self.fbbh2.GetHistory()
        if value not in history:
            history.append(value)
            self.fbbh2.SetHistory(history)
            self.fbbh2.GetHistoryControl().SetStringSelection(value)

def OnClickEbtn1(self,evt):
    sys.exit()


def OnClickDbtn1(self,evt):
    pass

def OnClickEbtn2(self,evt):
    pass

def OnClickDbtn2(self,evt):
    pass

程序无法进入 def OnClickEbtn1(self,evt)回调函数,请熟悉wxpython的大神帮忙解决,谢谢

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!