現在のディレクトリに特定の画像を表示するプログラムを書いています。オブジェクトを作成する前にwx.Image
、画像が存在するかどうかをチェックします。画像が存在しない場合は、「画像 'Tsukuyo.jpg' を開けません」というメッセージ ダイアログが表示されます。その後、プログラムは自動的に終了します。
ただし、実行すると(インタラクティブシェルによると)終了しましたが、ウィンドウは応答しませんでした。それはなぜですか?これがコードです。
class MyFrame(wx.Frame):
"""Frame class."""
def __init__(self, parent=None, id=-1,
pos=wx.DefaultPosition,
title='Hello, Tsukuyo!', size=(200,100)):
"""Create a Frame instanc."""
wx.Frame.__init__(self, parent, id, title, pos, size)
class MyApp(wx.App):
"""Application class."""
def OnInit(self):
return True
def main():
app = MyApp()
try:
with open('Tsukuyo.jpg'): pass
except IOError:
frame = MyFrame()
frame.Show()
dlg = wx.MessageDialog(frame, "Can not open image 'Tsukuyo.jpg'.",
"Error", wx.OK)
dlg.ShowModal()
dlg.Destroy()
wx.Frame.Close(frame, True)
app.ExitMainLoop()
sys.exit(0)
## Nothing goes wrong? Show the picture.
## blah blah blah