wxpython FileDialog在windows xp中打开崩溃程序

时间:2014-03-24 12:18:24

标签: python wxpython

我正在尝试将简单的FileDialog放入我的应用程序中。这是一个简单的例子:frame有1个按钮和1个statictext。按钮单击打开文件对话框后出现。当用户选择文件时 - 它的路径和名称被加载到statictext标签:

Frame1.py:

#Boa:Frame:Frame1

import wx

def create(parent):
    return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1STATICTEXT1, 
] = [wx.NewId() for _init_ctrls in range(3)]

class Frame1(wx.Frame):
    def _init_ctrls(self, prnt):
    # generated method, don't edit
    wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
          pos=wx.Point(383, 279), size=wx.Size(441, 126),
          style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
    self.SetClientSize(wx.Size(441, 126))

    self.button1 = wx.Button(id=wxID_FRAME1BUTTON1, label=u'load',
          name='button1', parent=self, pos=wx.Point(48, 72),
          size=wx.Size(328, 32), style=0)
    self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
          id=wxID_FRAME1BUTTON1)

    self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1,
          label='no file selected', name='staticText1', parent=self,
          pos=wx.Point(48, 32), size=wx.Size(76, 17), style=0)

def __init__(self, parent):
    self._init_ctrls(parent)

def OnButton1Button(self, event):
    dlg = wx.FileDialog(self, 'Choose file...', '.', '', '*.txt', wx.OPEN)
    try:
        if dlg.ShowModal() == wx.ID_OK:
            self.staticText1.SetLabel(dlg.GetPath())
        else:
            self.staticText1.SetLabel('no file selected')     
    finally:
        dlg.Destroy()

PyApp1.py:

#!/usr/bin/env python
#Boa:PyApp:main

import wx
import Frame1

modules ={'Frame1': [0, '', u'Frame1.py']}

class BoaApp(wx.App):
    def OnInit(self):
        self.main = Frame1.create(None)
        self.main.Show()
        self.SetTopWindow(self.main)
        return True

def main():
    application = BoaApp(0)
    application.MainLoop()

if __name__ == '__main__':
    main()

它在ubuntu和Windows 7上工作正常。在Windows XP(SP3)上,一旦用户点击按钮就会崩溃(甚至没有打开文件对话框)...请帮助:)

0 个答案:

没有答案