如何在wxpython中修复布局堆叠

2024-09-28 21:52:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图显示ssh连接所需的连接设置,我使用wx.BoxSizer来安排布局,不幸的是,布局不起作用,并将所有元素堆叠在左上角(直到我通过缩放/最大化调整窗口大小)

我已经尝试使用:self.Update()、self.Refresh()和self.Layout() 在我调用self.Show(True)方法之后,但这对我不起作用。 如果我删除了“状态栏设置”和“创建菜单栏”部分,它会工作,但我需要它们

import wx
import connectionSettingsProperties
import connectionSettings
from pubsub import pub

class MyFrame(wx.Frame):
    def __init__(self,parent,title):
        wx.Frame.__init__(self, parent, title = title, size = (1600,800))
        panel = wx.Panel(self)

        #statusbar setup
        self.CreateStatusBar()

        # menu setup
        filemenu = wx.Menu()

        # creating the menubar
        menuBar = wx.MenuBar()
        menuBar.Append(filemenu,"Menu")
        self.SetMenuBar(menuBar)

        #connectionstatus init
        self.ipLabel = wx.StaticText(panel, label = 'ip:')
        self.usernameLabel = wx.StaticText(panel, label = 'username:')

        #building layout
        vboxMain = wx.BoxSizer(wx.VERTICAL)
        hboxConnection = wx.BoxSizer(wx.HORIZONTAL)
        hboxConnection.Add(self.ipLabel)
        hboxConnection.Add(self.usernameLabel)
        vboxMain.Add(hboxConnection)
        panel.SetSizer(vboxMain)

        #show content
        self.Show(True)

app = wx.App(False)
frame = MyFrame(None, 'MyApp')
app.MainLoop()

这是它最初显示的:https://imgur.com/VQebA9t 这就是它的样子:https://imgur.com/60V1tcF 第二个结果将在我重新缩放窗口时显示


Tags: importselfaddtruetitleinitshow布局