为了账号安全,请及时绑定邮箱和手机立即绑定

wxPython - 侧边工具栏

wxPython - 侧边工具栏

德玛西亚99 2021-12-26 15:43:17
我们都知道 wxPython 工具栏大部分时间都是放在最上面的。但是有没有办法把它放在一边(最好是左边)?有没有办法把这段代码(取自这里)的顶部工具栏变成侧边工具栏:#!/usr/bin/env python3# -*- coding: utf-8 -*-"""ZetCode wxPython tutorialThis example creates a simple toolbar.author: Jan Bodnarwebsite: www.zetcode.comlast modified: April 2018"""import wxclass 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()
查看完整描述

1 回答

?
慕沐林林

TA贡献2016条经验 获得超9个赞

利用工具栏Style属性。


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(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()

//img1.sycdn.imooc.com//61c81d460001fff503470244.jpg

可用款式:

  • 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 之后的新样式。


查看完整回答
反对 回复 2021-12-26
  • 1 回答
  • 0 关注
  • 1103 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号