wxPython - Ubuntu中的空白帧

时间:2012-02-10 02:59:41

标签: python wxpython

我在wxPython中编写了一个基本的应用程序。虽然它在Windows下工作正常,但在Linux(Ubuntu 11.10)下,框架将显示为空(除了左侧的一些小的破碎元素)。控制台中没有错误。就在运行之前,我按照http://wiki.wxpython.org/InstallingOnUbuntuOrDebian

安装了wxPython

任何想法都赞赏。

class MainWindow(wx.Frame):
def __init__(self, parent, title):
    self.dirname=''

    # A "-1" in the size parameter instructs wxWidgets to use the default size.
    wx.Frame.__init__(self, parent, title=title, size=(400,500),style=wx.DEFAULT_FRAME_STYLE & ~ (wx.RESIZE_BORDER | wx.RESIZE_BOX | wx.MAXIMIZE_BOX))
    self.CreateStatusBar() # A Statusbar in the bottom of the window
    panel = wx.Panel(self, wx.ID_ANY)

    # Setting up the menus
    filemenu = wx.Menu()
    editmenu = wx.Menu()

    menuOpen = filemenu.Append(wx.ID_OPEN, "&Open"," Open an underway netCDF to load")
    menuAbout= filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
    menuExit = filemenu.Append(wx.ID_EXIT,"E&xit"," Terminate the program")
    menuConfig = editmenu.Append(wx.ID_EDIT, "&Config", "Edit Configuration")

    # Creating the menubar.
    menuBar = wx.MenuBar()
    menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
    menuBar.Append(editmenu,"&Edit")
    self.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame content.

    #Sizer setup.
    sizer = wx.BoxSizer(wx.VERTICAL) #root sizer
    buttonSizer = wx.BoxSizer(wx.HORIZONTAL)

    #Buttons.
    self.buttonLoadData = wx.Button(panel, -1, "&Load Data")
    self.buttonAbort = wx.Button(panel, -1, "&Abort Load")
    self.buttonAbort.Enabled = False
    self.buttonLoadData.Enabled = False

    #Slider. Should probably be a floating point spin control.
    #self.sliderRate = wx.Slider(panel, -1, 5, 0, 100, wx.DefaultPosition, (380, -1), wx.SL_AUTOTICKS | wx.SL_LABELS)
    self.sliderRate = self.FloatSlider(panel, -1, 1000, 0, 5000, wx.DefaultPosition, (380, -1), wx.SL_AUTOTICKS | wx.SL_LABELS)

    #Log window.
    self.log = wx.TextCtrl(self, style=wx.TE_MULTILINE | wx.TE_READONLY)


    # Events.
    self.Bind(wx.EVT_MENU, self.OnOpen, menuOpen)
    self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
    self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)
    self.Bind(wx.EVT_MENU, self.OnConfig, menuConfig)
    self.Bind(wx.EVT_BUTTON, self.OnLoadButton, self.buttonLoadData)
    self.Bind(wx.EVT_BUTTON, self.OnAbortButton, self.buttonAbort)
    self.Bind(wx.EVT_SLIDER, self.OnSlider)

    #Subscribe to messages from underlying simulator
    Publisher().subscribe(self.updateDisplay, "update")

    #Layout sizers
    buttonSizer.Add(self.buttonLoadData, 0, wx.ALL, 5)
    buttonSizer.Add(self.buttonAbort, 0, wx.ALL, 5)
    sizer.Add(buttonSizer, 0, wx.ALL, 5)
    sizer.Add(self.sliderRate, 0, wx.ALL, 5)
    sizer.Add(self.log, 1, wx.EXPAND, 5)

    panel.SetSizer(sizer)
    panel.Layout()

1 个答案:

答案 0 :(得分:1)

您可能忘记在sizer.Fit(panel)SetSizer之间添加Layout,以确保wxPython正确计算布局。我不知道为什么它在Windows上运行,但在Linux上我无法在没有wxPython的情况下正确显示Fit帧:

    panel.SetSizer(sizer)
    sizer.Fit(panel)
    panel.Layout()

这应该这样做。