wxglade列表树显示不正确

时间:2019-04-04 22:07:00

标签: python-3.x wxglade

我是wxglade的新手,正在尝试创建一个表单来显示选项卡和拆分窗口。左窗格上将有树列表。问题是,当我打开表单时,它会显示树列表,但是列表无法折叠或展开。当我转到第二个选项卡并返回第一个选项卡时,树形列表显示在小框中。

import wx

# Define the tab content as classes:
class TabOne(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)



        self.SetSize((400, 300))
        self.window_1 = wx.SplitterWindow(self, wx.ID_ANY)
        self.window_1_pane_1 = wx.ScrolledWindow(self.window_1, wx.ID_ANY, style=wx.BORDER_RAISED | wx.TAB_TRAVERSAL)
        #self.button_1 = wx.Button(self.window_1_pane_1, wx.ID_ANY, "button_1")

        #t = wx.StaticText(self, -1, "This is the first tab", (100,100)) start list
        il = wx.ImageList(16,16)

        self.fldridx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, (16,16)))
        self.fldropenidx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN,   wx.ART_OTHER, (16,16)))
        self.fileidx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, (16,16)))

        self.tree = wx.TreeCtrl(self, style=wx.TR_DEFAULT_STYLE | wx.TR_EDIT_LABELS)

        self.tree.AssignImageList(il)

        root = self.tree.AddRoot("Server")
        self.tree.SetItemData(root, None)
        self.tree.SetItemImage(root, self.fldridx,wx.TreeItemIcon_Normal)
        self.tree.SetItemImage(root, self.fldropenidx,wx.TreeItemIcon_Expanded)

        tree = ["A","B","C","D","E","F","G","H"]

        self.AddTreeNodes(root, tree)

        self.tree.Expand(root)



    def AddTreeNodes(self, parentItem, items):
        for item in items:
            if type(item) == str:
                newItem = self.tree.AppendItem(parentItem, item)
                self.tree.SetItemData(newItem, None)
                #self.tree.SetItemImage(newItem, self.fileidx,wx.TreeItemIcon_Normal)
            else:
                newItem = self.tree.AppendItem(parentItem, item[0])
                self.tree.SetItemPyData(newItem, None)
                #self.tree.SetItemImage(newItem, self.fldridx,wx.TreeItemIcon_Normal)
                self.tree.SetItemImage(newItem, self.fldropenidx,wx.TreeItemIcon_Expanded)

                self.AddTreeNodes(newItem, item[1])



#end list

        self.window_1_pane_2 = wx.Panel(self.window_1, wx.ID_ANY)

        self.window_1_pane_1.SetMinSize((50, 256))
        self.window_1_pane_1.SetBackgroundColour(wx.Colour(216, 216, 191))
        self.window_1_pane_1.SetScrollRate(10, 10)
        self.window_1.SetMinimumPaneSize(20)

        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
        #sizer_2.Add(self.button_1, 0, 0, 0)
        sizer1 = wx.BoxSizer(wx.VERTICAL)
        sizer1.Add(self.tree, 20, wx.EXPAND)
        self.SetSizer(sizer1)

        self.window_1_pane_1.SetSizer(sizer_2)
        self.window_1.SplitVertically(self.window_1_pane_1, self.window_1_pane_2)
        sizer_1.Add(self.window_1, 1, wx.EXPAND, 0)
        self.SetSizer(sizer_1)



class TabTwo(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        t = wx.StaticText(self, -1, "This is the second tab", (20,20))

class TabThree(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        t = wx.StaticText(self, -1, "This is the third tab", (20,20))

class TabFour(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        t = wx.StaticText(self, -1, "This is the last tab", (20,20))


class MainFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title="wxPython tabs example @pythonspot.com")

        # Create a panel and notebook (tabs holder)
        p = wx.Panel(self)
        nb = wx.Notebook(p)

        # Create the tab windows
        tab1 = TabOne(nb)
        tab2 = TabTwo(nb)
        tab3 = TabThree(nb)
        tab4 = TabFour(nb)

        # Add the windows to tabs and name them.
        nb.AddPage(tab1, "Tab 1")
        nb.AddPage(tab2, "Tab 2")
        nb.AddPage(tab3, "Tab 3")
        nb.AddPage(tab4, "Tab 4")

        # Set noteboook in a sizer to create the layout
        sizer = wx.BoxSizer()
        sizer.Add(nb, 1, wx.EXPAND)
        p.SetSizer(sizer)





if __name__ == "__main__":
    app = wx.App(redirect=True)
    MainFrame().Show()
    app.MainLoop()

1 个答案:

答案 0 :(得分:0)

wx.TreeCtrl具有内置的水平和垂直滚动条。因此,我猜这里不需要使用wx.ScrolledWindow。我将TabStripPlacement="Left"的代码简化为以下代码:

class TabOne

现在可以正常工作了。