windowsxp中wxpython文件对话框打开崩溃程序

2024-06-02 08:55:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将简单的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:

^{pr2}$

它在ubuntu和windows7上运行良好。在WindowsXP(SP3)上,一旦用户点击按钮(甚至没有出现“打开文件”对话框),它就会崩溃。。。请帮助:)


Tags: 文件selfidsizeinitdef按钮frame