📜  PyGTK-箭头类

📅  最后修改于: 2020-11-08 08:02:14             🧑  作者: Mango


gtk.Arrow对象用于绘制指向四个基本方向的简单箭头。该类继承自gtk.Misc类,并且该对象将占用为其分配的任何空间,例如Label或Button小部件。

通常,使用以下构造函数创建Arrow对象-

Arr = gtk.Arrow(arrow_type, shadow_type)

预定义的arrow_type常量为-

  • gtk.ARROW_UP
  • gtk.ARROW_DOWN
  • gtk.ARROW_LEFT
  • gtk.ARROW_RIGHT

下表中列出了预定义的shadow_type常量-

gtk.SHADOW_NONE No outline.
gtk.SHADOW_IN The outline is beveled inward.
gtk.SHADOW_OUT The outline is beveled outward like a button.
gtk.SHADOW_ETCHED_IN The outline itself is an inward bevel, but the frame bevels outward.
gtk.SHADOW_ETCHED_OUT The outline is an outward bevel, frame bevels inward.

在以下示例中,四个Button小部件被添加到Hbox。在每个按钮的顶部放置一个分别指向UP,DOWN,LEFT和RIGHT的gtk.Arrow对象。 HBOX容器在Alignment容器的帮助下放置在顶层窗口的底部。

遵守代码-

import gtk

class PyApp(gtk.Window):
   
   def __init__(self):
      super(PyApp, self).__init__()
      self.set_title("Arrow Demo")
      self.set_size_request(300, 200)
      self.set_position(gtk.WIN_POS_CENTER)
        
      vbox = gtk.VBox(False, 5)
      hbox = gtk.HBox(True, 3)
      valign = gtk.Alignment(0, 1, 0, 0)
      vbox.pack_start(valign)
        
      arr1 = gtk.Arrow(gtk.ARROW_UP, gtk.SHADOW_NONE)
      arr2 = gtk.Arrow(gtk.ARROW_DOWN, gtk.SHADOW_NONE)
      arr3 = gtk.Arrow(gtk.ARROW_LEFT, gtk.SHADOW_NONE)
      arr4 = gtk.Arrow(gtk.ARROW_RIGHT, gtk.SHADOW_NONE)
        
      btn1 = gtk.Button()
      btn1.add(arr1)
      btn2 = gtk.Button()
      btn2.add(arr2)
      btn3 = gtk.Button()
      btn3.add(arr3)
      btn4 = gtk.Button()
      btn4.add(arr4)
        
      hbox.add(btn1)
      hbox.add(btn2)
      hbox.add(btn3)
      hbox.add(btn4)
        
      halign = gtk.Alignment(0.5, 0.5, 0, 0)
      halign.add(hbox)
        
      vbox.pack_start(halign, False, True, 10)
      self.add(vbox)
      self.connect("destroy", gtk.main_quit)
      self.show_all()

PyApp()
gtk.main()

上面的代码将生成以下输出-

箭演示