wxPython:如何在状态栏中定位额外的小部件?

时间:2017-10-01 19:02:21

标签: user-interface drop-down-menu wxpython statusbar

我设法通过将Choice作为子项添加到状态栏中的wx.Choice,理论上它确实显示在右侧区域: Choice widget in status bar 问题:

  1. 很明显,Choice小部件会隐藏状态栏的文本。
  2. 我找不到任何方法将我的选择放在右边 窗口。
  3. 您可以猜到,我的目标是在窗口右侧对齐Choice项目,并确保状态栏的文本窗格尊重Choice的存在。

1 个答案:

答案 0 :(得分:0)

import wx

class MainFrame(wx.Frame):

    def __init__(self):
        wx.Frame.__init__(self, None, title='Statusbar',size=(300,200))
        panel = wx.Panel(self)
        status_btn = wx.Button(panel, label='Get Statusbar Info')
        status_btn.Bind(wx.EVT_BUTTON, self.on_status)
        self.statusbar = self.CreateStatusBar(2)
        w1 = self.statusbar.Size[0]
        w1= w1 - 50
        self.statusbar.SetStatusWidths([w1, -1])
        self.statusbar.SetMinHeight(30)
        self.statusbar.SetStatusText('Statusbar field 1')
        self.mychoices = wx.Choice(self.statusbar, wx.ID_ANY, choices=[("en"), ("it"), ("de")])
        self.mychoices.SetSelection(0)
        self.mychoices.SetPosition((w1+2, 2))
        self.Show()

    def on_status(self, event):
        print self.statusbar.GetStatusText()
        print self.mychoices.GetSelection()
        print self.mychoices.GetString(self.mychoices.GetSelection())

if __name__ == '__main__':
    app = wx.App()
    frame = MainFrame()
    app.MainLoop()

enter image description here