如何为大文本固定每行的按钮,使其看起来像预期的输出,几乎所有按钮都像墙壁一样对齐。
不工作:
预期输出:
代码:无法对齐
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()