没有合适的资源?快使用搜索试试~ 我知道了~
在写桌面软件时,通常会使用到托盘上的泡泡提示功能,让我们来看看使用python如何实现这个小功能。 一、Linux系统 在Linux上,实现一个气泡提示非常简单,使用GTK实现的pynotify模块提供了些功能,我的环境是Ubuntu,默认安装此模块,如果没有,下载源文件编译安装一个。实现代码如下: #!/usr/bin/python #coding:utf-8 import pynotify pynotify.init (Bubble@Linux) bubble_notify = pynotify.Notification (Linux上的泡泡提示, 看,比Windows上实现方
资源推荐
资源详情
资源评论
python实现桌面气泡提示功能实现桌面气泡提示功能
在写桌面软件时,通常会使用到托盘上的泡泡提示功能,让我们来看看使用python如何实现这个小功能。
一、一、Linux系统系统
在Linux上,实现一个气泡提示非常简单,使用GTK实现的pynotify模块提供了些功能,我的环境是Ubuntu,默认安装此模块,如果没
有,下载源文件编译安装一个。实现代码如下:
#!/usr/bin/python
#coding:utf-8
import pynotify
pynotify.init ("Bubble@Linux")
bubble_notify = pynotify.Notification ("Linux上的泡泡提示", "看,比Windows上实现方便多了!")
bubble_notify.show ()
效果:
二、二、Windows下的实现下的实现
Windows下实现是比较复杂的,没有pynotify这样一个模块,找到了一个还算不错的模块(地址),这个类有些语法上的小问题,至少在
python2.6下如此,需要修改一下,如下是修改后的代码),基本可用,代码如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#gtkPopupNotify.py
#
# Copyright 2009 Daniel Woodhouse
# modified by NickCis 2010 http://github.com/NickCis/gtkPopupNotify
# Modifications:
# Added: * Corner support (notifications can be displayed in all corners
# * Use of gtk Stock items or pixbuf to render images in notifications
# * Posibility of use fixed height
# * Posibility of use image as background
# * Not displaying over Windows taskbar(taken from emesene gpl v3)
# * y separation.
# * font description options
# * Callbacks For left, middle and right click
#
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU Lesser General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU Lesser General Public License for more details.
#
#You should have received a copy of the GNU Lesser General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import gtk
import pango
import gobject
# This code is used only on Windows to get the location on the taskbar
# Taken from emesene Notifications (Gpl v3)
taskbarOffsety = 0
taskbarOffsetx = 0
if os.name == "nt":
import ctypes
from ctypes.wintypes import RECT, DWORD
user = ctypes.windll.user32
MONITORINFOF_PRIMARY = 1
HMONITOR = 1
class MONITORINFO(ctypes.Structure):
_fields_ = [
('cbSize', DWORD),
('rcMonitor', RECT),
('rcWork', RECT),
('dwFlags', DWORD)
]
taskbarSide = "bottom"
taskbarOffset = 30
info = MONITORINFO()
info.cbSize = ctypes.sizeof(info)
info.dwFlags = MONITORINFOF_PRIMARY
user.GetMonitorInfoW(HMONITOR, ctypes.byref(info))
if info.rcMonitor.bottom != info.rcWork.bottom:
taskbarOffsety = info.rcMonitor.bottom - info.rcWork.bottom
if info.rcMonitor.top != info.rcWork.top:
taskbarSide = "top"
taskbarOffsety = info.rcWork.top - info.rcMonitor.top
if info.rcMonitor.left != info.rcWork.left:
taskbarSide = "left"
taskbarOffsetx = info.rcWork.left - info.rcMonitor.left
if info.rcMonitor.right != info.rcWork.right:
taskbarSide = "right"
taskbarOffsetx = info.rcMonitor.right - info.rcWork.right
class NotificationStack:
def __init__(self, size_x=300, size_y=-1, timeout=5, corner=(False, False), sep_y=0):
"""
Create a new notification stack. The recommended way to create Popup instances.
Parameters:
`size_x` : The desired width of the notifications.
`size_y` : The desired minimum height of the notifications. If it isn't set,
or setted to None, the size will automatically adjust
`timeout` : Popup instance will disappear after this timeout if there
is no human intervention. This can be overridden temporarily by passing
a new timout to the new_popup method.
`coner` : 2 Value tuple: (true if left, True if top)
`sep_y` : y distance to separate notifications from each other
"""
self.size_x = size_x
self.size_y = -1
if (size_y == None):
pass
剩余6页未读,继续阅读
资源评论
weixin_38705004
- 粉丝: 5
- 资源: 946
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 仓库管理系统 基于Spring Boot框架实现的仓库管理系统(程序+数据库+报告)
- An Efficient Representation for Irradiance Environment Maps
- grafana的服务器监控模板
- OneForAll子域收集工具
- KUKA机器人MxAutomation功能资料
- PHP免登录购买商城源码/抖音商城系统/主播带货手机商城/支持分站/对接易支付
- 全新完整版H5商城系统源码 亲测 附教程
- 2021年全球疾病负担研究(GBD)生育率估计.zip
- 基于曼宁公式求解复式断面水位-流量关系曲线(MATLAB全代码)
- 前端常用布局模板39套,纯CSS实现布局
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功