📜  wxPython | Python中的GetToolBitmapSize()函数

📅  最后修改于: 2022-05-13 01:54:37.761000             🧑  作者: Mango

wxPython | Python中的GetToolBitmapSize()函数

在本文中,我们将学习 wxPython 的 GetToolBitmapSize()函数。 GetToolBitmapSize() 返回工具栏期望的位图大小。

默认位图大小取决于平台:例如,MSW 为 16×15,GTK 为 24×24。此大小不一定表示给定平台上用于工具栏的最佳大小,为此您应该使用 ArtProvider::GetNativeSizeHint(wxART_TOOLBAR) 但无论如何,由于位图大小是从相关位图的大小自动推导出来的将工具添加到工具栏后,通常无需显式调用 SetToolBitmapSize。

代码示例:

Python3
wx.ToolBar.GetToolBitmapSize(self)


Python3
No Parameters in GetToolBitmapSize() function.


输出 :

wx.Size

代码示例 2:

Python3

import wx
 
 
class Example(wx.Frame):
    global count
    count = 0;
 
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
 
        self.InitUI()
 
    def InitUI(self):
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
        pnl = wx.Panel(self)
        self.toolbar = self.CreateToolBar()
        self.toolbar.SetMargins(10, 10)
        # Add Tools Using AddTool function
        rtool = self.toolbar.AddTool(13, 'twoTool', wx.Bitmap('wrong.png'), shortHelp ="Simple Tool2")
        stool = self.toolbar.AddTool(14, 'twoTool', wx.Bitmap('wrong.png'), shortHelp ="Simple Tool")
 
        self.toolbar.Realize()
        self.SetSize((350, 250))
        self.SetTitle('Control')
        self.Centre()
 
        # print tool bitmap size
        print(self.toolbar.GetToolBitmapSize())
 
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
 
 
if __name__ == '__main__':
    main()

输出:

import wx
 
class Example(wx.Frame):
    global count
    count = 0;
 
    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs)
 
        self.InitUI()
 
    def InitUI(self):
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
        pnl = wx.Panel(self)
        self.toolbar = self.CreateToolBar()
        self.toolbar.SetMargins(10, 10)
        # Add Tools Using AddTool function
        rtool = self.toolbar.AddTool(13, 'twoTool', wx.Bitmap('user.png'), shortHelp ="Simple Tool2")
 
        self.toolbar.Realize()
        self.SetSize((350, 250))
        self.SetTitle('Control')
        self.Centre()
 
        # print tool bitmap size
        print(self.toolbar.GetToolBitmapSize())
 
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
 
 
if __name__ == '__main__':
    main()