您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

python中wx将图标显示在右下角的脚本代码

2026/1/3 14:54:01发布16次查看
复制代码 代码如下:
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()
class myframe(wx.frame):
    def __init__(self):
        wx.frame.__init__(self, none, -1, my frame, size=(300, 300))
        panel = wx.panel(self, -1)
        panel.bind(wx.evt_motion,  self.onmove)
        wx.statictext(panel, -1, pos:, pos=(10, 12))
        self.posctrl = wx.textctrl(panel, -1, , pos=(40, 10))
try:
            self.tbicon = demotaskbaricon(self)
        except:
            self.tbicon = none
#wx.callafter(self.showtip)
#self.bind(wx.evt_close, self.onclosewindow)
        #self.bind(wx.evt_iconize, self.oniconfiy)
    def onclosewindow(self, event):
        self.dying = true
        self.demopage = none
        self.codepage = none
        self.mainmenu = none
        if self.tbicon is not none:
            self.tbicon.destroy()
        self.destroy()
    def oniconfiy(self, evt):
        wx.logmessage(oniconfiy: %s % evt.iconized())
        evt.skip()
    def onmove(self, event):
        pos = event.getposition()
        self.posctrl.setvalue(%s, %s % (pos.x, pos.y))
if __name__ == '__main__':
    app = wx.pysimpleapp()
    frame = myframe()
    frame.show(true)
    app.mainloop()
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product