PyGobject(八)布局容器之Button篇——Gtk.LinkButton
来源:互联网 发布:淘宝跳失率多少正常 编辑:程序博客网 时间:2024/06/06 18:11
- GtkLinkButton
- 继承关系
- Methods
- Virtual Methods
- Properties
- Signals
- 例子
- 安装gvfs
Gtk.LinkButton
继承关系
Gtk.LinkButton是带有链接文本的按钮。Gtk.LinkButton是Gtk.Button的直接子类
Methods
Virtual Methods
Properties
Signals
例子
代码:
#!/usr/bin/env python3# Created by xiaosanyu at 16/6/14# section 009TITLE = "LinkButton"DESCRIPTION = """A Gtk.LinkButton is a Gtk.Button with a hyperlink, similar to the one used by web browsers,which triggers an action when clicked.It is useful to show quick links to resources.The ::activate-link signal is emitted each time the Gtk.LinkButton has been clicked.The default handler will call Gtk.show_uri() with the URI stored inside the Gtk.LinkButton :uri property.To override the default behavior, you can connect to the ::activate-link signaland stop the propagation of the signal by returning True from your handler.you need to install gvfs to get support for uri schemes such as http:// or ftp://,as only local files are handled by GIO itself"""import giimport webbrowsergi.require_version('Gtk', '3.0')from gi.repository import Gtkclass LinkButtonWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="LinkButton Demo") self.set_border_width(10) # button = Gtk.LinkButton(uri="file:///Users/xiaosanyu/mydocbook/docbook.html", label="Visit GTK+ Homepage") button = Gtk.LinkButton(uri="http://www.gnome.org", label="Visit GTK+ Homepage") button.connect("activate-link", self.visit) self.add(button) def visit(self, btn): webbrowser.open(btn.get_uri()) return Truedef main(): win = LinkButtonWindow() win.connect("delete-event", Gtk.main_quit) win.show_all() Gtk.main()if __name__ == "__main__": main()
创建一个Gtk.LinkButton,绑定“activate-link”信号到visit方法
button = Gtk.LinkButton(uri="http://www.gnome.org", label="Visit GTK+ Homepage") button.connect("activate-link", self.visit) self.add(button)def visit(self, btn): webbrowser.open(btn.get_uri()) return True
当点击链接时,执行visit方法,使用Python自带webbrowser模块打开URI。并且返回True。
说明:默认点击时如果报错
Unable to show ‘http://www.gnome.org‘: 不支持该操作
需要安装“gvfs”
安装gvfs
jhbuild build gvfs
这个模块装起来比较麻烦,遇到各种各样的问题,最后装上后,点击链接依然报这个错,遂放弃。
如有在MAC上直接能打开此链接的同学,还请告知方法~~
代码下载地址:http://download.csdn.net/detail/a87b01c14/9594728
0 0
- PyGobject(八)布局容器之Button篇——Gtk.LinkButton
- PyGobject(五)布局容器之Button篇——Gtk.Button
- PyGobject(六)布局容器之Button篇——Gtk.ColorButton
- PyGobject(七)布局容器之Button篇——Gtk.FontButton
- PyGobject(九)布局容器之Button篇——Gtk.ToggleButton
- PyGobject(十)布局容器之Button篇——Gtk.CheckButton
- PyGobject(十一)布局容器之Button篇——Gtk.RadioButton
- PyGobject(十二)布局容器之Button篇——Gtk.MenuButton
- PyGobject(十四)布局容器之Button篇——Gtk.LockButton
- PyGobject(十五)布局容器之Button篇——Gtk.ScaleButton
- PyGobject(十六)布局容器之Button篇——Gtk.VolumeButton
- PyGobject(十七)布局容器之Button篇——Gtk.ModelButton
- PyGobject(十三)布局容器之Button篇——图片按钮和圆形按钮
- PyGobject(十八)布局容器之ActionBar
- PyGobject(十九)布局容器之Alignment
- PyGobject(三十)布局容器之StackSidebar
- PyGobject(三十一)布局容器之EventBox
- PyGobject(三十二)布局容器之Window
- 炒股的四类投资法
- Swift开发UITableView常用的一些细节知识点介绍
- Appium的ios环境搭建、真机运行app
- Raspberry pi2串口通信
- 2016夏季练习——AC自动机
- PyGobject(八)布局容器之Button篇——Gtk.LinkButton
- 跨站点请求伪造
- 最全的常用正则表达式大全
- android studio tabhost基础 多功能时钟app 实现闹钟功能(一)
- [LeetCode] 52. N-Queens II
- Android UI高级之RecyclerView
- SourceTree+OSChina+CocoaPods提交时,Pods提交失败解决办法:
- RecyclerView控件补充
- *** glibc detected *** free(): invalid pointer:解决方法