0

ここに直接コードがあり、何千もの言葉で説明する価値があります。

#!/usr/bin/env python2

import wx

class TestDialog(wx.Dialog):
    def __init__self(*arg, **args):
        wx.Dialog.__init__(self, parent, id, title, size=(350,300))
        sizer = self.CreateTextSizer('My Buttons')
        # bad()
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(wx.Button(self, -1, 'Button'), 0, wx.ALL, 5)
        sizer.Add(wx.Button(self, -1, 'Button'), 0, wx.ALL, 5)
        sizer.Add(wx.Button(self, -1, 'Button'), 0, wx.ALL, 5)
        sizer.Add(wx.Button(self, -1, 'Button'), 0, wx.ALL|wx.ALIGN_CENTER, 5)
        sizer.Add(wx.Button(self, -1, 'Button'), 0, wx.ALL|wx.EXPAND, 5)
        sizer.Fit(self)
        self.SetSizer(sizer)

    def InitUI(self):
        pnl = wx.Panel(self)
        vbox = wx.BoxSizer(wx.VERTICAL)
        btn = wx.Button(pnl, label='Ok')
        vbox.Add(btn, 1, flag=wx.LEFT)
        pnl.SetSizer(vbox)

    def OnClose(self):
        self.Destroy()


class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(550,500))

        panel = wx.Panel(self, -1)
        wx.Button(panel, 1, 'Show Custom Dialog', (100,100))
        self.Bind (wx.EVT_BUTTON, self.OnShowCustomDialog)

    def OnShowCustomDialog(self, event):
        dia = TestDialog(self, -1, 'buttons')
        dia.ShowModal()
        # dia.Destroy()

if __name__ == "__main__":
    try:
        app = wx.App()
        frame = MyFrame(None, wx.ID_ANY, 'dialog')
        frame.Show()
        # import wx.lib.inspection
        # wx.lib.inspection.InspectionTool().Show()
        app.MainLoop()
    except:
        import sys
        import traceback
        xc = traceback.format_exception(*sys.exc_info())
        wx.MessageBox(''.join(xc))

メイン ウィンドウが表示されますが、ダイアログが表示された後に何も実行されないようです。呼び出しのコメントを外しても、bad()何も表示されないようです。

4

1 に答える 1

2

これを変える:

class TestDialog(wx.Dialog):
    def __init__self(*arg, **args):

これに:

class TestDialog(wx.Dialog):
    def __init__(self, parent, id, title)

それはあなたのタイプミスだと思います。上記のように変更すると、必要な結果が得られます。インスタンスを作成すると、クラスの__init__メソッドが自動的に実行されます。明示的に呼び出されない限り、__init__selfメソッドは決して実行されません。

于 2013-05-16T15:02:16.010 に答える