简体   繁体   English

如何在GTK Python中更改VScale的大小

[英]How to change size of VScale in GTK Python

I have added a gtk.VScale() to my GUI and the size is really small, but why ? 我在我的GUI中添加了一个gtk.VScale(),它的大小确实很小,但是为什么呢?

I have this code sample : 我有此代码示例:

def __init__(self, parent, grid):
    self.parent = parent

    self.tooltips = gtk.Tooltips()

    self.ajustement = gtk.Adjustment(0.0, 0.0, 101.0, 0.1, 1.0, 1.0)
    self.scaleH = gtk.VScale(self.ajustement)

    self.bt_lumiere = gtk.ToggleButton()
    self.bt_lumiere.set_active(False)
    self.bt_lumiere.set_image(gtk.image_new_from_file('data/icons/moon.jpg'))
    self.bt_lumiere.connect("pressed",self.on_changer_etat_lumiere)

    self.barreLumiere = BarreLuminosite(self)

    box = gtk.VBox(False,5)
    box.pack_start(self.bt_lumiere, True)
    box.pack_start(self.scaleH,True)

    grid.attach(self.align(box, padright=1, padleft=1), 1,2,1,5)

def align(self, widget, xalign=0, yalign=0.5, padtop=0, padbottom=0, padleft=0, padright=0):
    ali = gtk.Alignment(xalign=xalign, yalign=yalign)
    ali.add(widget)
    ali.set_padding(padtop, padbottom, padleft, padright)
    return ali

The result : 结果 : 结果 Thanks in advance. 提前致谢。

You didn't specify the Gtk or the python version, so it's difficult to answer. 您没有指定Gtk或python版本,因此很难回答。 This code is for Gtk 3, and Python 3, using introspection. 这段代码使用自省功能,适用于Gtk 3和Python 3。 Maybe this helps: 也许这会有所帮助:

hbox = Gtk.HBox()
large_label = Gtk.Label("Large label")
self.ajuste = Gtk.Adjustment(0.0, 0.0, 101.0, 0.1, 1.0, 10)
self.vscale = Gtk.VScale.new(self.ajuste)

vbox = Gtk.VBox()
lbl = Gtk.Image.new_from_icon_name( "system-run", Gtk.IconSize.DND)
vbox.pack_start(lbl, False, False, 0)
vbox.pack_start(self.vscale, True, True, 0)

hbox.pack_start(large_label, False, False, 0)
hbox.pack_start(vbox, False, False, 0)

self.add(hbox)
self.show_all()

Note that in vbox.pack_start for the vscale , the sizing options are True , so that the scale can expand. 请注意,在vbox.pack_startvscale ,调整大小选项为True ,以便扩大比例。

You can also call set_size_request on the scale, and you can change the margins with set_margin_left , set_margin_right , _bottom and _top . 您还可以按比例调用set_size_request ,并可以使用set_margin_leftset_margin_right_bottom_top更改边距。 The result of the above code is: 上面的代码的结果是:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM