对齐框架wxpython中的列表框

对齐框架wxpython中的列表框,python,listbox,wxpython,boxsizer,Python,Listbox,Wxpython,Boxsizer,我正在尝试找出如何正确对齐列表框。我一插入ListBox的行,布局就会变得一团糟 #!/usr/bin/python # -*- coding: utf-8 -*- import wx oplist=[] with open("options.txt","r") as f: for line in f: oplist.append(line.rstrip('\n')) print(oplist) class Example(wx

我正在尝试找出如何正确对齐列表框。我一插入ListBox的行,布局就会变得一团糟

#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx

oplist=[]
with open("options.txt","r") as f:
    for line in f:
        oplist.append(line.rstrip('\n'))
print(oplist)

class Example(wx.Frame):

    def __init__(self, parent, title):
        super(Example, self).__init__(parent, title = title, size=(200,300))

        self.InitUI()
        self.Centre()
        self.Show()

    def InitUI(self):
        p = wx.Panel(self)
        vbox= wx.BoxSizer(wx.VERTICAL)
        self.l1 = wx.StaticText(p, label="Enter number", style=wx.ALIGN_CENTRE)
        vbox.Add(self.l1, -1, wx.ALIGN_CENTER_HORIZONTAL, 200)
        self.b1 = wx.Button(p, label="Buton 1")
        vbox.Add(self.b1, -1, wx.ALIGN_CENTER_HORIZONTAL,100)
        self.flistbox= wx.ListBox(self,choices=oplist, size=(100,100), name="Field", wx.ALIGN_CENTER_HORIZONTAL)
        vbox.Add(self.flistbox, -1, wx.CENTER, 10)
        p.SetSizer(vbox)
        
app = wx.App()
Example(None, title="BoxSizer")
app.MainLoop()
以下是有无以下情况的输出:

正在使用self将列表框设置为帧的父级

self.flistbox= wx.ListBox(
    self,choices=oplist, size=(100,100), name="Field", wx.ALIGN_CENTER_HORIZONTAL)
它应该像其他控件一样使用p作为面板的父对象

self.flistbox= wx.ListBox(
    p,choices=oplist, size=(100,100), name="Field", wx.ALIGN_CENTER_HORIZONTAL)