【发布时间】:2013-12-18 11:38:16
【问题描述】:
我正在学习使用 wxPython 构建一个基于对话的程序。
我尝试了以下代码(简单地从 wxPython Demo 复制):
import wx
#---------------------------------------------------------------------------
class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
wx.Panel.__init__(self, parent, -1)
b = wx.Button(self, -1, "Create and Show a DirDialog", (50,50))
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
def OnButton(self, evt):
# In this case we include a "New directory" button.
dlg = wx.DirDialog(self, "Choose a directory:",
style=wx.DD_DEFAULT_STYLE
#| wx.DD_DIR_MUST_EXIST
#| wx.DD_CHANGE_DIR
)
# If the user selects OK, then we process the dialog's data.
# This is done by getting the path data from the dialog - BEFORE
# we destroy it.
if dlg.ShowModal() == wx.ID_OK:
self.log.WriteText('You selected: %s\n' % dlg.GetPath())
# Only destroy a dialog after you're done with it.
dlg.Destroy()
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
win = TestPanel(nb, log)
return win
#---------------------------------------------------------------------------
overview = """\
This class represents the directory chooser dialog. It is used when all you
need from the user is the name of a directory. Data is retrieved via utility
methods; see the <code>DirDialog</code> documentation for specifics.
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
我在Python IDLE 和Apatana Studio 3 中都运行了上面的代码。这是我得到的。
在Python IDLE,我有:
IDLE 子进程:sys.argv 中没有传递 IP 端口。
在Apatana Studio 3,我有:
回溯(最近一次通话最后一次):
文件“C:\Users\User\My Documents\Aptana Studio 3 Workspace\Test Dialogue\main.py”,第 61 行,在 import run ImportError: No module named run
我可以知道我错了吗?非常感谢。 :)
【问题讨论】: