wxpython 窗口图标和托盘图标
来源:互联网 发布:绫濑水泥杀人案知乎 编辑:程序博客网 时间:2024/05/28 05:14
import wxclass App(wx.App): def OnInit(self): frame = wx.Frame(parent=None, title='Bare') frame.Show() icon=wx.EmptyIcon() icon.LoadFile("loadIcon.ico",wx.BITMAP_TYPE_ICO) frame.SetIcon(icon) frame.tbicon=wx.TaskBarIcon() frame.tbicon.SetIcon(icon,"wxPython Demo") return Trueapp = App()app.MainLoop()
这里有个问题:托盘图标只是显示出来了,并没有响应任何事件。继续研究。
续:找到完整的托盘程序
import wxclass TaskBarIcon(wx.TaskBarIcon): ID_Hello = wx.NewId() def __init__(self, frame): wx.TaskBarIcon.__init__(self) self.frame = frame self.SetIcon(wx.Icon(name='loadIcon.ico', type=wx.BITMAP_TYPE_ICO), 'TaskBarIcon!') self.Bind(wx.EVT_TASKBAR_LEFT_DCLICK, self.OnTaskBarLeftDClick) self.Bind(wx.EVT_MENU, self.OnHello, id=self.ID_Hello) def OnTaskBarLeftDClick(self, event): if self.frame.IsIconized(): self.frame.Iconize(False) if not self.frame.IsShown(): self.frame.Show(True) self.frame.Raise() def OnHello(self, event): wx.MessageBox('Hello From TaskBarIcon!', 'Prompt')# override def CreatePopupMenu(self): menu = wx.Menu() menu.Append(self.ID_Hello, 'Hello') return menuclass Frame(wx.Frame): def __init__( self, parent=None, id=wx.ID_ANY, title='TaskBarIcon', pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE): wx.Frame.__init__(self, parent, id, title, pos, size, style)# wx.Frame.SetIcon(wx.Icon('Wand.ico', wx.BITMAP_TYPE_ICO))# The above line is invalid: method become callable after bounding to the instance self.SetIcon(wx.Icon('loadIcon.ico', wx.BITMAP_TYPE_ICO)) panel = wx.Panel(self, wx.ID_ANY) button = wx.Button(panel, wx.ID_ANY, 'Hide Frame', pos=(60, 60)) self.Bind(wx.EVT_BUTTON, self.OnHide, button)# button = wx.Button(panel, wx.ID_ANY, 'Close', pos=(60, 100))# self.Bind(wx.EVT_BUTTON, self.OnClose, button) self.Bind(wx.EVT_CLOSE, self.OnClose) self.Bind(wx.EVT_ICONIZE, self.OnIconfiy) # What is the meaning? self.taskBarIcon = TaskBarIcon(self) sizer = wx.BoxSizer() sizer.Add(button, 0) panel.SetSizer(sizer) def OnHide(self, event): self.Hide() def OnIconfiy(self, event): wx.MessageBox('Frame has been iconized!', 'Prompt') event.Skip() def OnClose(self, event): self.taskBarIcon.Destroy() self.Destroy()def TestFrame(): app = wx.PySimpleApp() frame = Frame(size=(640, 480)) frame.Centre() frame.Show() app.MainLoop()if __name__ == '__main__': TestFrame()
另外一种方式:(推荐用第一种方法)
# -*- coding: UTF-8 -*-import wxfrom wx import Frameclass MyFrame(Frame): def __init__(self, parent, id, title): Frame.__init__(self, parent, id, title) self.Bind(wx.EVT_MOVE, self.OnMove) self.Bind(wx.EVT_SIZE, self.OnSize) icon = wx.EmptyIcon() icon.CopyFromBitmap(wx.BitmapFromImage(wx.Image(("katon.png"), wx.BITMAP_TYPE_PNG))) self.SetIcon(icon) def OnSize(self, event): size = event.GetSize() print "size:", size.width, size.height def OnMove(self, event): pos = event.GetPosition() print "pos:", pos.x, pos.yclass MyApp(wx.App): def OnInit(self): frame = MyFrame(None, -1, u"测试") frame.Show(True) self.SetTopWindow(frame) return Truedef main(): app = MyApp(0) app.MainLoop()if __name__ == "__main__": main()
此种方法的png图片只能是32X32的,否则会加载不成功。
- wxpython 窗口图标和托盘图标
- 窗口最小化为托盘图标
- 托盘图标
- 托盘图标
- 托盘图标
- 托盘图标
- 托盘图标
- wxPython中添加窗口标题图标
- 修改 QQ 任务栏托盘区小图标和等级图标
- QT 创建托盘图标和右键菜单
- QT 创建托盘图标和右键菜单
- 托盘图标的添加和消息响应
- VC++ 添加托盘图标和气泡
- qt生成应用程序图标和托盘
- 托盘图标的删除和托盘程序的优化
- Java程序添加托盘图标和托盘弹出菜单
- MFC下托盘图标的实现和托盘菜单
- DuiVision开发教程(11)-托盘图标和托盘菜单
- 常见的进制表示方式和转换
- DATAGUARD原理
- 下无字幕的美剧方法
- JS保留两位小数 四舍五入函数toFixed()
- IIS 返回状态解释
- wxpython 窗口图标和托盘图标
- 关于iphone scrollview的问题
- Android ApiDemos示例解析(59):Graphics->ColorFilters
- 跳转页面,定时 (html+jsp+js)
- 这些年我们爱犯的弱智错误(菜鸟必看)(JavaScript)
- 成为高手的必经之路——学会调试代码(菜鸟必读)(JavaScript)
- Js操作cookie的函数,来自jquery
- fl2440按键中断驱动
- sizeof测试程序,C专家上的