尝试添加aui窗格时wxpython GUI崩溃

时间:2013-03-14 02:56:57

标签: python wxpython

我正在处理我正在处理的GUI问题。通过单击按钮创建窗格两次,然后每次关闭它。当我第三次尝试创建它时会冻结。我将代码限制在此:

import wx
import wx.aui as aui

class Controller:
    def __init__(self, app):
        self.view = Frame()
        self.view.btn.Bind(wx.EVT_BUTTON, self.onBtn)

    def onBtn(self, event):
        self.view.CreateTicket()

class Frame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, size=(600,400))

        self.panel = wx.Panel(self)

        self.ticketPanel = wx.Panel(self.panel)
        self.ticketPanel.Hide()     
        self.btn = wx.Button(self.panel)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.btn)

        self.panel.SetSizer(sizer)

        self.CreatePain()        
        self.Layout()
        self.Show()

    def CreatePain(self):       
        self.mgr = aui.AuiManager(self.panel,
                   aui.AUI_MGR_DEFAULT
                 | aui.AUI_MGR_TRANSPARENT_DRAG
                 | aui.AUI_MGR_ALLOW_ACTIVE_PANE)

    def CreateTicket(self):

        self.mgr.AddPane(self.ticketPanel, aui.AuiPaneInfo().
                         Caption("TradeTicket").
                         Float().FloatingPosition((200,100)).
                         FloatingSize(wx.Size(50, 50)).MinimizeButton(True))
        self.mgr.Update()

if __name__ == "__main__":
    app = wx.App(False)
    controller = Controller(app)
    app.MainLoop()

1 个答案:

答案 0 :(得分:0)

我认为问题在于您将相同的wx.Panel实例(self.ticketPanel)添加为窗格。尝试为每个窗格创建一个新窗格。