Advertisement
Guest User

popovermenu.py

a guest
Aug 7th, 2015
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. import gi
  2. gi.require_version("Gtk", "3.0")
  3. from gi.repository import Gtk
  4.  
  5. def on_click(button):
  6.     #Toggle
  7.     if popover.get_visible():
  8.         popover.hide()
  9.     else:
  10.         popover.show_all()
  11.  
  12. #Creating the window
  13. window = Gtk.Window(title="Popover")
  14. window.connect("destroy", lambda w: Gtk.main_quit())
  15.  
  16. #Creating and placing a button
  17. box = Gtk.Box(orientation = Gtk.Orientation.VERTICAL)
  18. button = Gtk.Button.new_from_icon_name("open-menu-symbolic", 1)
  19. button.connect("clicked", on_click)
  20. box.add(button)
  21. window.add(box)
  22.  
  23. #Creating a popover
  24. popover = Gtk.PopoverMenu.new()
  25. popover.set_relative_to(button)
  26.  
  27. pbox = Gtk.Box(orientation = Gtk.Orientation.VERTICAL)
  28. popover.add(pbox)
  29.  
  30. one = Gtk.ModelButton.new()
  31. one.set_label("Button One")
  32. pbox.pack_start(one, False, False, 0)
  33.  
  34. two = Gtk.ModelButton.new()
  35. two.set_label("Button Two")
  36. pbox.pack_start(two, False, False, 0)
  37.  
  38. three = Gtk.ModelButton.new()
  39. three.set_label("Button Three")
  40. pbox.pack_start(three, False, False, 0)
  41.  
  42. window.set_size_request(200, 200)
  43. window.show_all()
  44.  
  45. Gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement