wxPython wx.ToolBar中的SetToolBitmapSize()函数
在这篇文章中,我们将学习与wxPythpon的wx.ToolBar类相关的SetToolBitMapSize()函数。设置每个工具位图的默认大小。默认的位图大小是16×15像素。它只接受尺寸作为参数。
语法。
wx.ToolBar.SetToolBitmapSize(self, size)
参数。
参数 | 输入类型 | 描述 |
---|---|---|
size | wx.Size | 工具栏中位图的大小。 |
代码示例 1:
import wx
class Example(wx.Frame):
def __init__(self, *args, **kwargs):
super(Example, self).__init__(*args, **kwargs)
self.InitUI()
def InitUI(self):
self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
self.toolbar = self.CreateToolBar()
td = self.toolbar.AddTool(1, 'right', wx.Bitmap('user.png'))
self.toolbar.Realize()
self.Bind(wx.EVT_TOOL, self.OnOne, td)
self.SetSize((350, 250))
self.SetTitle('Undo redo')
self.Centre()
def OnOne(self, e):
# set bitmap size in toolbar
self.toolbar.SetToolBitmapSize(size =(32, 32))
# Realize() called to finalize new added tools
self.toolbar.Realize()
def OnQuit(self, e):
self.Close()
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
输出:
点击前 :
点击后 :
代码示例2:
import wx
class Example(wx.Frame):
def __init__(self, *args, **kwargs):
super(Example, self).__init__(*args, **kwargs)
self.InitUI()
def InitUI(self):
self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
self.toolbar = self.CreateToolBar()
td = self.toolbar.AddTool(1, 'right', wx.Bitmap('right.png'))
self.toolbar.Realize()
self.Bind(wx.EVT_TOOL, self.OnOne, td)
self.SetSize((350, 250))
self.SetTitle('Undo redo')
self.Centre()
def OnOne(self, e):
# set bitmap size in toolbar
self.toolbar.SetToolBitmapSize(size =(60, 60))
# Realize() called to finalize new added tools
self.toolbar.Realize()
def OnQuit(self, e):
self.Close()
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
输出:
点击前 :
点击后 :