Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Gtk3 controlling button size

The button size should be controlled by packing HBox in VBox but my two buttons still have size depending on text:

    first=Gtk.VBox()
    second=Gtk.HBox()
    third=Gtk.VBox()
    fourth=Gtk.HBox()
    but1=Gtk.Button(label="any title")
    first.pack_start(second,False,False,0)
    third.pack_start(fourth,False,False,0)        
    first.pack_start(but1,False,False,0)
    self.data_wp="title of label"
    self.label_data=Gtk.Label(label=self.data_wp)
    Gtk.Widget.set_size_request(but1,85,15)
    but2=Gtk.Button(label=self.data_wp)
    Gtk.Container.add(but2,self.label_data)
    Gtk.Widget.set_size_request(but2,85,15)

What am I doing wrong? I add button title from label but it shoudn't be the problem, and I tried to set title directly on button - nothing changed. I tried to use only one set of VBox,HBox, but it gave no effect too.

like image 678
mpruchni Avatar asked Jan 01 '16 12:01

mpruchni


1 Answers

I think the problem here is that you're trying to resize the button using the set_size_request() method of the Gtk.Widget. But set_size_request() only set the minimum size of the widget, so it can still be larger.

I don't know if there is a method to resize the button, but there are the properties width-request and height-request of the Gtk.Widget that you can use.
In your code, it would be:
bt1.set_property("width-request", 85)
bt1.set_property("height-request", 15)

like image 127
keiwop Avatar answered Oct 01 '22 20:10

keiwop