Mar*_*Lux 3 notification python quickly application-development
如果我在终端中使用以下命令创建一个快速项目:
quickly create ubuntu-application helloworld
Run Code Online (Sandbox Code Playgroud)
然后在 HelloworldWindow.py 中添加以下几行,
import sys
import pynotify
Run Code Online (Sandbox Code Playgroud)
当我想运行应用程序时,“import pynotify”行在我的系统上产生以下错误输出
quickly run
Run Code Online (Sandbox Code Playgroud)
错误输出:
/usr/lib/python2.7/dist-packages/gobject/constants.py:24:警告:g_boxed_type_register_static:断言
g_type_from_name (name) == 0' failed import gobject._gobject /usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:40: Warning: specified class size for type
PyGtkGenericCellRenderer' 小于父类型的GtkCellRenderer' class size from gtk import _gtk /usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:40: Warning: g_type_get_qdata: assertion
节点 != NULL' 从 gtk import _gtk 失败
应用程序不会启动。
但是如果我想运行以下 python-application
#!/usr/bin/python
import sys
import pynotify
if __name__ == "__main__":
if not pynotify.init("icon-summary-body"):
sys.exit(1)
n = pynotify.Notification(
"Notification",
"Hello notify! It works!",
"notification-message-im")
n.show()
Run Code Online (Sandbox Code Playgroud)
例如,通过将代码保存在文件名“notify.py”中,我可以在终端中使用命令运行代码:
python notify.py
Run Code Online (Sandbox Code Playgroud)
并且通知工作正常!
via快速创建的python应用程序有什么问题??为什么导入不起作用?我是快速和python的新手。
我刚刚遇到了完全相同的问题。
这是我的解决方案。
from gi.repository import Notify
Notify.init ('Application')
notification = Notify.Notification.new ('Title', 'Message', 'dialog-information')
notification.show ()
Run Code Online (Sandbox Code Playgroud)