wxPython – wx.Button 中的 GetBitmap()函数
在本文中,我们将学习与 wxPython 的 wx.Button 类关联的 GetBitmap()函数。 GetBitmap()函数仅用于返回按钮显示的位图。
仅当按钮不显示任何图像时,返回的位图可能无效
Syntax: wx.Button.GetBitmap(self)
Parameters: No parameters in GetBitmap() function.
Return Type: wx.Bitmap
代码示例:
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)
# create parent panel for button
self.pnl = wx.Panel(self)
# create wx.Bitmap object
bmp = wx.Bitmap('pointer.png')
# create button at point (20, 20)
self.st = wx.Button(self.pnl, id = 1, label ="Button", pos =(20, 20),
size =(100, 30), name ="button")
# set bmp as bitmap for button
self.st.SetBitmap(bmp)
# get wx.Bitmap object
bmap = self.st.GetBitmap()
# print depth of bitmap
print(bmp.Depth)
self.SetSize((350, 250))
self.SetTitle('wx.Button')
self.Centre()
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
控制台输出:
32
输出窗口: