![](/img/trans.png)
[英]Is it possible to put a toolbar button on the right side of it using wxpython?
[英]wxPython - A side toolbar
我们都知道,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()
利用工具栏的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()
可用样式:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.