0

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

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

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 当我重新调整窗口时,第二个结果就会显示出来。

4

1 回答 1

0

你真的很亲近。您应该只添加以下行:

vboxMain.Fit(panel)

下线:

panel.SetSizer(vboxMain)
于 2019-07-02T20:43:59.477 回答