How to block size of last column in treeview gtk3
Question: Below a demo treeview. I would like to fixed the width of the last column.

After a lot of test with different command, I ask help.

<https://andrewsteele.me.uk/learngtk.org/tutorials/python_gtk3_tutorial/html/treeviewcolumn.html>

it's said: The sizing of the column can also be customised in a number of ways
depending on the change in the content by using the method:

treeviewcolumn.set_sizing(sizing)

The sizing argument can be set to Gtk.TreeViewColumnSizing.GROW_ONLY sets the
column to never shrink regardless of the content,
Gtk.TreeViewColumnSizing.AUTOSIZE adjusts the column to be an optimal size and
is updated everytime the model changes, and Gtk.TreeViewColumnSizing.FIXED
which sets columns to be a fixed pixel width.

With my code, in fact the last column is taking the available space

    
    
    #!/usr/bin/env python3
    # -*- coding: ISO-8859-1 -*-
    # liststore.py
    from gi.repository import Gtk,Gdk
    
    window = Gtk.Window()
    window.connect("destroy", lambda q: Gtk.main_quit())
    
    liststore = Gtk.ListStore(str, int)
    liststore.append(["Oranges", 5])
    liststore.append(["Apples", 3])
    liststore.append(["Bananas", 1])
    liststore.append(["Tomatoes", 4])
    liststore.append(["Cucumber", 1])
    liststore.append(["potatoes", 10])
    liststore.append(["apricot", 100])
    
    treeview = Gtk.TreeView(model=liststore)
    treeview.set_rules_hint( True )
    window.add(treeview)
    
    treeviewcolumn = Gtk.TreeViewColumn("Item")
    
    treeview.append_column(treeviewcolumn)
    cellrenderertext = Gtk.CellRendererText()
    treeviewcolumn.pack_start(cellrenderertext, True)
    treeviewcolumn.add_attribute(cellrenderertext, "text", 0)
    
    treeviewcolumn = Gtk.TreeViewColumn("Quantity")
    treeviewcolumn.props.sizing = Gtk.TreeViewColumnSizing.FIXED
    
    
    treeview.append_column(treeviewcolumn)
    cellrenderertext = Gtk.CellRendererText()
    treeviewcolumn.pack_start(cellrenderertext, True)
    treeviewcolumn.add_attribute(cellrenderertext, "text", 1)
    css_provider = Gtk.CssProvider()
    css = """
                    /* font operate on entire GtkTreeView not for selected row */
                    GtkTreeView {
                        text-shadow: 1px 1px 2px black, 0 0 1em blue, 0 0 0.2em blue;
                        color: white;
                        font: 1.5em Georgia, "Bitstream Charter", "URW Bookman L", "Century Schoolbook L", serif;
                        font-weight: bold;
                        font-style: italic;box-shadow: 5px 3px red;}
                    GtkTreeView row:nth-child(even) {
                    background-image: -gtk-gradient (linear,
                                                       left top,
                       left bottom,
                       from (#d0e4f7),
                       color-stop (0.5, darker (#d0e4f7)),
                       to (#fdffff));
                    }
                    GtkTreeView row:nth-child(odd) {
                    background-image: -gtk-gradient (linear,
                                                       left top,
                       left bottom,
                       from (yellow),
                       color-stop (0.5, darker (yellow)),
                       to (#fdffff));
                    }
                    /* next line only border action operate */
                    GtkTreeView:selected{color: white; background: green; border-width: 1px; border-color: black;}
                    /* next line for Gtk.TreeViewColumn */
                    column-header .button{color: white; background: purple;}
    
                """
    css_provider.load_from_data(css)
    screen = Gdk.Screen.get_default()
    style_context = window.get_style_context()
    style_context.add_provider_for_screen(screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
    
    window.show_all()
    Gtk.main()
    


Answer: In your case the issue is that GTK tries to fill up the space in someway, as
none of the column was set to expand the last column will expand. So in order
to fix your issue change your code as follows:

    
    
    treeviewcolumn = Gtk.TreeViewColumn("Item")
    treeviewcolumn.set_expand(True)
    treeview.append_column(treeviewcolumn)
    

This will tell GTK that you want the Item column to expand, by default this
value is `False` so the other column (like the "Quantity" column) will not
expand.

