python中的wx库_python中wx将图标显示在右下脚的代码

python中wx将图标显示在右下脚的代码: 代码如下:

import wx

import images

class DemoTaskBarIcon(wx.TaskBarIcon):

TBMENU_RESTORE = wx.NewId()

TBMENU_CLOSE   = wx.NewId()

TBMENU_CHANGE  = wx.NewId()

TBMENU_REMOVE  = wx.NewId()

def __init__(self, frame):

wx.TaskBarIcon.__init__(self)

self.frame = frame

# Set the image

icon = self.MakeIcon(images.getWXPdemoImage())

self.SetIcon(icon, "wxPython Demo")

self.imgidx = 1

# bind some events

self.Bind(wx.EVT_TASKBAR_LEFT_DCLICK, self.OnTaskBarActivate)

self.Bind(wx.EVT_MENU, self.OnTaskBarActivate, id=self.TBMENU_RESTORE)

self.Bind(wx.EVT_MENU, self.OnTaskBarClose, id=self.TBMENU_CLOSE)

self.Bind(wx.EVT_MENU, self.OnTaskBarChange, id=self.TBMENU_CHANGE)

self.Bind(wx.EVT_MENU, self.OnTaskBarRemove, id=self.TBMENU_REMOVE)

def CreatePopupMenu(self):

"""

This method is called by the base class when it needs to popup

the menu for the default EVT_RIGHT_DOWN event.  Just create

the menu how you want it and return it from this function,

the base class takes care of the rest.

"""

menu = wx.Menu()

menu.Append(self.TBMENU_RESTORE, "Restore wxPython Demo")

menu.Append(self.TBMENU_CLOSE,   "Close wxPython Demo")

menu.AppendSeparator()

menu.Append(self.TBMENU_CHANGE, "Change the TB Icon")

menu.Append(self.TBMENU_REMOVE, "Remove the TB Icon")

return menu

def MakeIcon(self, img):

"""

The various platforms have different requirements for the

icon size...

"""

if "wxMSW" in wx.PlatformInfo:

img = img.Scale(16, 16)

elif "wxGTK" in wx.PlatformInfo:

img = img.Scale(22, 22)

# wxMac can be any size upto 128x128, so leave the source img alone....

icon = wx.IconFromBitmap(img.ConvertToBitmap() )

return icon

def OnTaskBarActivate(self, evt):

if self.frame.IsIconized():

self.frame.Iconize(False)

if not self.frame.IsShown():

self.frame.Show(True)

self.frame.Raise()

def OnTaskBarClose(self, evt):

self.frame.Close()

def OnTaskBarChange(self, evt):

names = [ "WXPdemo", "Mondrian", "Pencil", "Carrot" ]

name = names[self.imgidx]

getFunc = getattr(images, "get%sImage" % name)

self.imgidx += 1

if self.imgidx >= len(names):

self.imgidx = 0

icon = self.MakeIcon(getFunc())

self.SetIcon(icon, "This is a new icon: " + name)

def OnTaskBarRemove(self, evt):

self.RemoveIcon()

备注:以上程序摘自wxdemo,不够完善,仅供学习参考。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值