gpt4 book ai didi

python - 在框架wxpython中对齐列表框

转载 作者:太空宇宙 更新时间:2023-11-04 05:23:24 25 4
gpt4 key购买 nike

我正在尝试弄清楚如何正确对齐 ListBox。一旦我插入 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()

这里有和没有的输出: With ListBox Without

最佳答案

列表框通过使用 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)

关于python - 在框架wxpython中对齐列表框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39579580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com