PyGobject(十二)布局容器之Button篇——Gtk.MenuButton
来源:互联网 发布:仓管员用什么软件 编辑:程序博客网 时间:2024/06/05 03:59
- GtkMenuButton
- 继承关系
- Methods
- Virtual Methods
- Properties
- Signals
- 例子
Gtk.MenuButton
继承关系
Gtk.MenuButton菜单按钮,点击时可以弹出一个菜单或者气泡。Gtk.MenuButton是Gtk.ToggleButton的直接子类
Methods
Virtual Methods
Properties
Signals
例子
代码:
#!/usr/bin/env python3# Created by xiaosanyu at 16/6/14# section 013TITLE = "MenuButton"DESCRIPTION = """The Gtk.MenuButton widget is used to display a popup when clicked on.This popup can be provided either as a Gtk.Menu, a Gtk.Popover or an abstract Gio.MenuModel."""import gigi.require_version('Gtk', '3.0')from gi.repository import Gtkitems = ["EditCopy", "EditPaste", "EditSomething"]class MenuButtonWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="MenuButton Demo") self.set_border_width(10) self.set_size_request(250, 200) hbox = Gtk.VBox(spacing=6) self.add(hbox) button = Gtk.MenuButton("Menu Button popover") # 距离顶部50 button.props.margin_top = 50 # set_direction 如果有多余空间才会在指定的方向上显示气泡 button.set_direction(Gtk.ArrowType.UP) popover = self.create_popover(button, Gtk.Label("show popover"), Gtk.PositionType.TOP) button.set_popover(popover) hbox.pack_start(button, False, False, 0) button = Gtk.MenuButton("Menu Button popup") button.props.margin_bottom = 50 hbox.pack_end(button, False, False, 0) menu = Gtk.Menu.new() for item in items: item = Gtk.MenuItem(label=item) item.connect("activate", self.on_menu_selected) item.show() menu.append(item) button.set_popup(menu) @staticmethod def create_popover(parent, child, pos): popover = Gtk.Popover(relative_to=parent) popover.set_position(pos) popover.add(child) popover.set_border_width(6) child.show() return popover @staticmethod def on_menu_selected(widget, *args): print("Menu item " + widget.get_label() + " was selected")def main(): win = MenuButtonWindow() win.connect("delete-event", Gtk.main_quit) win.show_all() Gtk.main()if __name__ == "__main__": main()
创建第一个Gtk.MenuButton,设置距离容器顶部50
button = Gtk.MenuButton("Menu Button popover")button.props.margin_top = 50
设置在button上方弹出气泡
button.set_direction(Gtk.ArrowType.UP)
创建一个Gtk.Popover(气泡窗口)
popover = self.create_popover(button, Gtk.Label("show popover"), Gtk.PositionType.TOP)@staticmethoddef create_popover(parent, child, pos): popover = Gtk.Popover(relative_to=parent) popover.set_position(pos) popover.add(child) popover.set_border_width(6) child.show() return popover
设置MenuButton点击时弹出这个popover
button.set_popover(popover)
创建第二个Gtk.MenuButton
button = Gtk.MenuButton("Menu Button popup")
创建一个Gtk.Menu(菜单)
menu = Gtk.Menu.new()for item in items: item = Gtk.MenuItem(label=item) item.connect("activate", self.on_menu_selected) item.show() menu.append(item)
绑定每一个菜单项“activate”信号,点击时执行on_menu_selected方法
@staticmethoddef on_menu_selected(widget, *args): print("Menu item " + widget.get_label() + " was selected")
设置MenuButton点击时弹出这个菜单
button.set_popup(menu)
代码下载地址:http://download.csdn.net/detail/a87b01c14/9594728
0 0
- PyGobject(十二)布局容器之Button篇——Gtk.MenuButton
- PyGobject(五)布局容器之Button篇——Gtk.Button
- PyGobject(六)布局容器之Button篇——Gtk.ColorButton
- PyGobject(七)布局容器之Button篇——Gtk.FontButton
- PyGobject(八)布局容器之Button篇——Gtk.LinkButton
- PyGobject(九)布局容器之Button篇——Gtk.ToggleButton
- PyGobject(十)布局容器之Button篇——Gtk.CheckButton
- PyGobject(十一)布局容器之Button篇——Gtk.RadioButton
- PyGobject(十四)布局容器之Button篇——Gtk.LockButton
- PyGobject(十五)布局容器之Button篇——Gtk.ScaleButton
- PyGobject(十六)布局容器之Button篇——Gtk.VolumeButton
- PyGobject(十七)布局容器之Button篇——Gtk.ModelButton
- PyGobject(十三)布局容器之Button篇——图片按钮和圆形按钮
- PyGobject(二十二)布局容器之Frame
- PyGobject(十八)布局容器之ActionBar
- PyGobject(十九)布局容器之Alignment
- PyGobject(三十)布局容器之StackSidebar
- PyGobject(三十一)布局容器之EventBox
- lintcode longest-increasing-continuous-subsequence 最长上升连续子序列
- 新博客
- jQuery中获取点击事件的元素及元素的id属性
- UnderstandingDSOLinkChange
- 让你的APP轻松加上扫描二维码功能
- PyGobject(十二)布局容器之Button篇——Gtk.MenuButton
- sql 执行顺序
- [Java基础笔记]可视化窗体部分
- 装饰(Decorator)模式
- uml类图(Class Diagram)中类与类之间的关系及表示
- 流媒体基础知识TS流 PS流 ES流区别
- MySQL开启针对mysql的所有操作log
- CSS盒子模型
- lvs+keepalived防火墙问题