0

我在 wxpython 中编写了一小段代码,其中拆分器窗口用于拆分对话框,一个面板具有自定义树 ctrl,另一个具有静态框。此代码在 Fedora 和 ubuntu 中运行良好,但在 Windows 中,对话框显示为空。

主要代码:

wx.Dialog.__init__(self, None, 6, 'Filters',size = (500,600) )
    self.splitter = wx.SplitterWindow(self, -1)
    leftPanel = wx.Panel(self.splitter, -1)
    leftBox = wx.BoxSizer(wx.VERTICAL)
    self.__tree = TreeFilter(leftPanel, 1)
    leftBox.Add(self.__tree, -1, wx.GROW)
    self.__tree.Bind(CT.EVT_TREE_ITEM_CHECKED, self.checked)
    leftPanel.SetSizer(leftBox)

    rightPanel = wx.Panel(self.splitter, -1)
    rightBox = wx.BoxSizer(wx.VERTICAL)
    self.display = wx.StaticText(rightPanel, -1, '', style=wx.ALIGN_LEFT)
    rightBox.Add(self.display, -1, wx.GROW)


    btnsizer = wx.StdDialogButtonSizer()
    btn = wx.Button(rightPanel, wx.ID_OK)
    btn.SetDefault()
    btnsizer.AddButton(btn)

    btn = wx.Button(rightPanel, wx.ID_CANCEL)
    btnsizer.AddButton(btn)
    btnsizer.Realize()
    rightBox.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
    rightPanel.SetSizer(rightBox)

    self.splitter.SplitVertically(leftPanel, rightPanel)
    self.Centre()

其中 TreeFilter 是自定义树 ctrl。请帮我解决问题

4

1 回答 1

0

问题是您没有将拆分器本身放在设置为扩展的sizer中。在我的屏幕上,你可以看到一个小盒子在左手角全部蜷缩起来,所以我知道发生了类似的事情。

这是一个对我有用的例子:

import wx

########################################################################
class MyTreeCtrl(wx.TreeCtrl):

    #----------------------------------------------------------------------
    def __init__(self, parent, id):
        wx.TreeCtrl.__init__(self, parent, id)


########################################################################
class TestDlg(wx.Dialog):
    """"""

    #----------------------------------------------------------------------
    def __init__(self):
        """Constructor"""

        wx.Dialog.__init__(self, None, 6, 'Filters',size = (500,600) )
        mainSizer = wx.BoxSizer(wx.VERTICAL)

        self.splitter = wx.SplitterWindow(self, -1)
        leftPanel = wx.Panel(self.splitter, -1)
        leftBox = wx.BoxSizer(wx.VERTICAL)
        self.tree = MyTreeCtrl(leftPanel, 1)

        self.root = self.tree.AddRoot("The Root Item")
        self.tree.SetPyData(self.root, None)
        for x in range(15):
            child = self.tree.AppendItem(self.root, "Item %d" % x)
            self.tree.SetPyData(child, None)
        self.tree.Expand(self.root)

        leftBox.Add(self.tree, -1, wx.GROW)
        #self.__tree.Bind(CT.EVT_TREE_ITEM_CHECKED, self.checked)
        leftPanel.SetSizer(leftBox)

        rightPanel = wx.Panel(self.splitter, -1)
        rightBox = wx.BoxSizer(wx.VERTICAL)
        self.display = wx.StaticText(rightPanel, -1, '', style=wx.ALIGN_LEFT)
        rightBox.Add(self.display, -1, wx.GROW)

        btnsizer = wx.StdDialogButtonSizer()
        btn = wx.Button(rightPanel, wx.ID_OK)
        btn.SetDefault()
        btnsizer.AddButton(btn)

        btn = wx.Button(rightPanel, wx.ID_CANCEL)
        btnsizer.AddButton(btn)
        btnsizer.Realize()
        rightBox.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
        rightPanel.SetSizer(rightBox)

        self.splitter.SplitVertically(leftPanel, rightPanel)
        self.Centre()
        mainSizer.Add(self.splitter, 1, wx.EXPAND)
        self.SetSizer(mainSizer)

#----------------------------------------------------------------------
if __name__ == "__main__":
    app = wx.App(False)
    dlg = TestDlg()
    dlg.Show()
    dlg.Destroy()
    app.MainLoop()
于 2012-05-21T14:49:56.607 回答