0

如何为大文本固定每行的按钮,使其看起来像预期的输出,几乎所有按钮都像墙壁一样对齐。

不工作:

在此处输入图像描述

预期输出:

在此处输入图像描述

代码:无法对齐

import gobject, gtk
gobject.threads_init()

class rightclick(object):
  def __init__(self):
    self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    self.window.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0, 0, 0))
    self.window.set_size_request(630, 480)
    self.window.set_border_width(1)
    self.window.set_title("PIPTPT")
    self.window.move(0,720 /3 - 200 )
    self.window.set_name("main window")
    self.window.connect("delete-event", gtk.main_quit)
    self.vbox = gtk.VBox()
    self.vbox.set_border_width(0)
    self.vbox.pack_start(self.create_bbox(True, "",5, gtk.BUTTONBOX_START), True, True, 0)
    self.window.add(self.vbox)

  def create_bbox(self, horizontal, title, spacing, layout):
      frame = gtk.Frame(title)
      frame.set_label_align( 0, 0)
      frame.set_shadow_type( gtk.SHADOW_NONE)
      frame.set_border_width(2)
      if horizontal:
          bbox = gtk.HButtonBox()
      else:
          bbox = gtk.VButtonBox()

      bbox.set_border_width(0)
      frame.add(bbox)
      bbox.set_layout(layout)
      bbox.set_spacing(0)
      button_height= 22
      for x in range(0, 35):
        button = gtk.Button()
        button.props.relief = gtk.RELIEF_NONE
        label = gtk.Label()
        label.set_markup('<span color="#bbbbbb"><small>Long Long Long</small></span>');
        button.add(label)
        button.set_size_request(48, button_height)
        button.connect("clicked" , self.button_quit , None)
        bbox.add(button)

      return frame

  def run(self):
    self.window.show_all()
    self.window.set_keep_above(True)
    if(self.window.get_window().get_state() == gtk.gdk.WINDOW_STATE_MAXIMIZED):
      self.window.unmaximize()
    gtk.main()

  def button_quit(self, widget, event):
    gtk.main_quit()

if __name__=='__main__':
    s=rightclick()
    s.run()
gobject.MainLoop.run()
4

1 回答 1

0

好的 - 这个例子是我正在寻找的,它有效。

#!/usr/bin/python
import gtk

class PyApp(gtk.Window):

    def __init__(self):
        super(PyApp, self).__init__()

        self.set_title("Calculator")
        self.set_size_request(250, 230)
        self.set_position(gtk.WIN_POS_CENTER)

        vbox = gtk.VBox(False, 2)
        table = gtk.Table(5, 4, True)

        table.attach(gtk.Button("Cls"), 0, 1, 0, 1)
        table.attach(gtk.Button("Bck"), 1, 2, 0, 1)
        table.attach(gtk.Label(), 2, 3, 0, 1)
        table.attach(gtk.Button("Close"), 3, 4, 0, 1)

        table.attach(gtk.Button("7"), 0, 1, 1, 2)
        table.attach(gtk.Button("8"), 1, 2, 1, 2)
        table.attach(gtk.Button("9"), 2, 3, 1, 2)
        table.attach(gtk.Button("/"), 3, 4, 1, 2)

        table.attach(gtk.Button("4"), 0, 1, 2, 3)
        table.attach(gtk.Button("5"), 1, 2, 2, 3)
        table.attach(gtk.Button("6"), 2, 3, 2, 3)
        table.attach(gtk.Button("*"), 3, 4, 2, 3)

        table.attach(gtk.Button("1"), 0, 1, 3, 4)
        table.attach(gtk.Button("2"), 1, 2, 3, 4)
        table.attach(gtk.Button("3"), 2, 3, 3, 4)
        table.attach(gtk.Button("-"), 3, 4, 3, 4)

        table.attach(gtk.Button("0"), 0, 1, 4, 5)
        table.attach(gtk.Button("."), 1, 2, 4, 5)
        table.attach(gtk.Button("="), 2, 3, 4, 5)
        table.attach(gtk.Button("+"), 3, 4, 4, 5)

        #vbox.pack_start(gtk.Entry(), False, False, 0)
        vbox.pack_end(table, True, True, 0)

        self.add(vbox)

        self.connect("destroy", gtk.main_quit)
        self.show_all()


PyApp()
gtk.main()
于 2013-10-15T10:45:24.357 回答