wxPython - 侧边工具栏

我们都知道 wxPython 工具栏大部分时间都是放在最上面的。但是有没有办法把它放在一边(最好是左边)?有没有办法把这段代码(取自这里)的顶部工具栏变成侧边工具栏:


#!/usr/bin/env python3

# -*- coding: utf-8 -*-


"""

ZetCode wxPython tutorial


This example creates a simple toolbar.


author: Jan Bodnar

website: www.zetcode.com

last modified: April 2018

"""


import wx



class Example(wx.Frame):


    def __init__(self, *args, **kwargs):

        super(Example, self).__init__(*args, **kwargs)


        self.InitUI()


    def InitUI(self):


        toolbar = self.CreateToolBar()

        qtool = toolbar.AddTool(wx.ID_ANY, 'Quit', wx.Bitmap('texit.png'))

        toolbar.Realize()


        self.Bind(wx.EVT_TOOL, self.OnQuit, qtool)


        self.SetSize((350, 250))

        self.SetTitle('Simple toolbar')

        self.Centre()


    def OnQuit(self, e):

        self.Close()



def main():


    app = wx.App()

    ex = Example(None)

    ex.Show()

    app.MainLoop()



if __name__ == '__main__':

    main()


德玛西亚99
浏览 1104回答 1
1回答

慕沐林林

利用工具栏Style属性。import wxclass Example(wx.Frame):    def __init__(self, *args, **kwargs):        super(Example, self).__init__(*args, **kwargs)        self.InitUI()    def InitUI(self):        toolbar = self.CreateToolBar(wx.TB_VERTICAL|wx.TB_TEXT)        atool = toolbar.AddTool(wx.ID_ANY, 'Tool_A', wx.Bitmap('stop.png'))        btool = toolbar.AddTool(wx.ID_ANY, 'Tool_B', wx.Bitmap('stop.png'))        ctool = toolbar.AddTool(wx.ID_ANY, 'Quit', wx.Bitmap('stop.png'))        toolbar.Realize()        self.Bind(wx.EVT_TOOL, self.OnQuit, ctool)        self.SetSize((350, 250))        self.SetTitle('Simple toolbar')        self.Centre()    def OnQuit(self, e):        self.Close()def main():    app = wx.App()    ex = Example(None)    ex.Show()    app.MainLoop()if __name__ == '__main__':    main()可用款式:wx.TB_FLAT:使工具栏看起来很扁平(仅适用于 Windows 和 GTK)。wx.TB_DOCKABLE:使工具栏可浮动和可停靠(仅限 GTK)。wx.TB_HORIZONTAL:指定水平布局(默认)。wx.TB_VERTICAL:指定垂直布局。wx.TB_TEXT:显示工具栏按钮中的文本;默认情况下只显示图标。wx.TB_NOICONS:指定工具栏按钮中没有图标;默认情况下会显示它们。wx.TB_NODIVIDER:指定工具栏上方没有分隔线(边框)(仅限 Windows)wx.TB_NOALIGN:指定不与父窗口对齐(仅适用于 Windows,不是很有用)。wx.TB_HORZ_LAYOUT:并排显示文本和图标,而不是垂直堆叠(仅限 Windows 和 GTK 2)。此样式必须与 TB_TEXT 一起使用。wx.TB_HORZ_TEXT:TB_HORZ_LAYOUT 和 TB_TEXT 的组合。wx.TB_NO_TOOLTIPS:当鼠标悬停在工具上时,不显示工具的简短帮助工具提示。wx.TB_BOTTOM:对齐父窗口底部的工具栏。wx.TB_RIGHT:对齐父窗口右侧的工具栏。wx.TB_DEFAULT_STYLE:TB_HORIZONTAL 和 TB_FLAT 的组合。这个样式是 wxWidgets 2.9.5 之后的新样式。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python