单击左窗格中的项目时如何在右窗格中显示列表?例如,根据代码,如果单击左窗格中的选项A,它将显示一个列表,但是如果单击B选项,则将在右窗格中显示另一个列表。
此外,我还想双击右窗格中的行以打开一个新的模式窗口。我还想在启动时以最大尺寸显示窗口。
import wx
import sys
# Define the tab content as classes:
class TabOne(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.SetSize((400, 100))
self.window_1 = wx.SplitterWindow(self, wx.ID_ANY)
self.tree = wx.TreeCtrl(self.window_1, style=wx.TR_DEFAULT_STYLE |
wx.TR_EDIT_LABELS)
root = self.tree.AddRoot("Server")
letters = []
il = ["A","B","C","D","E","F","G","H"]
ila = ["x","y","z"]
for letter in il:
item = self.tree.AppendItem(root, letter)
if letter == "C":
for ila1 in ila:
sub_item = self.tree.AppendItem(item, ila1)
self.window_1_pane_2 = wx.Panel(self.window_1, wx.ID_ANY)
players = [('R1', '10', '20'), ('R2', '30', '40'),
('R3', '50', '60'), ('R4', '70', '80'),
('R5', '90', '99')]
self.list = wx.ListCtrl(self.window_1_pane_2, -1, style =
wx.LC_REPORT)
self.list.InsertColumn(0, 'Col1', width = 100)
self.list.InsertColumn(1, 'Col2', wx.LIST_FORMAT_RIGHT, 100)
self.list.InsertColumn(2, 'Col3', wx.LIST_FORMAT_RIGHT, 100)
for i in players:
index = self.list.InsertItem(sys.maxsize, i[0])
self.list.SetItem(index, 1, i[1])
self.list.SetItem(index, 2, i[2])
self.window_1.SetMinimumPaneSize(20)
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_4 = wx.BoxSizer(wx.HORIZONTAL)
sizer_4.Add(self.list,1,wx.EXPAND)
self.window_1_pane_2.SetSizer(sizer_4)
self.window_1.SplitVertically(self.tree, self.window_1_pane_2)
sizer_1.Add(self.window_1, 1, wx.EXPAND, 0)
self.SetSizer(sizer_1)
def AddTreeNodes(self, parentItem, items):
for item in items:
if type(item) == str:
newItem = self.tree.AppendItem(parentItem, item)
self.tree.SetItemData(newItem, None)
else:
newItem = self.tree.AppendItem(parentItem, item[0])
self.tree.SetItemPyData(newItem, None)
self.tree.SetItemImage(newItem, self.fldropenidx,wx.TreeItemIcon_Expanded)
self.AddTreeNodes(newItem, item[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()