次のプログラムに変更を加える前は、すべてうまくいきました。
変更前のプログラム:
#! /usr/bin/env python
""" A bare-minimum wxPython program """
import wx
class MyApp(wx.App):
def OnInit(self):
return True
class MyFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title)
if __name__ == '__main__':
app = wx.App()
frame = MyFrame(None, "Sample")
frame.Show(True)
app.MainLoop()
しかしframe
、 の定義に入った後OnInit
、プログラムは構文エラーなしで実行されますが、何も表示されません:(
変更後のプログラム:
#! /usr/bin/env python
""" A bare-minimum wxPython program """
import wx
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, "Sample") ## add two lines here
self.frame.Show(True)
return True
class MyFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title)
if __name__ == '__main__':
app = wx.App()
app.MainLoop()
デバッガーを使用して、プログラムをステップ オーバーしてみます。定義されていないようですself.frame
(最初から最後まで表示されません)。
プログラムで何が問題になっていますか? 私はPythonとwxPythonを初めて使用します。助けてください。どうも。
編集:
app = MyApp()
標準出力/標準エラー出力:
NameError: global name 'Show' is not defined