Search code examples
pythonuser-interfacegtkpygtk

Vertical Scroll Bar in PyGTK


I made a combined text editor-terminal in Python using GTK. I want users to be able to control the amount of vertical space each occupies in the same window. I don't know how to do that, I need help, the suggested solutions I've searched online have not worked.

# UI

# Imort modules
import os
from gi.repository import Gtk, Vte
from gi.repository import GLib

from gi.repository import Gtk

class MainWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self)
        # Window title and Icon
        self.set_title("MaeTrics")
        # Vertical Box
        self.box = Gtk.VBox(homogeneous=False, spacing=0)
        self.add(self.box)
        # Scrolled Text Window
        scrolledwindow1 = Gtk.ScrolledWindow()
        scrolledwindow1.set_hexpand(True)
        scrolledwindow1.set_vexpand(True)
        self.textview = Gtk.TextView()
        self.textbuffer = self.textview.get_buffer()
        scrolledwindow1.add(self.textview)
        # Terminal
        # scrolledwindow2 = Gtk.ScrolledWindow()
        # scrolledwindow2.set_hexpand(True)
        # scrolledwindow2.set_vexpand(True)
        terminal     = Vte.Terminal()
        terminal.fork_command_full(Vte.PtyFlags.DEFAULT,os.environ['HOME'],["/bin/sh"],[],GLib.SpawnFlags.DO_NOT_REAP_CHILD,None,None,)
        # scrolledwindow2.add(terminal)
        # Pack everything in vertical box
        self.box.pack_start(scrolledwindow1, True, True, 0)
        self.box.pack_start(terminal,True,True,0)
        # Callback functions
        self.connect("delete-event", Gtk.main_quit)
        self.show_all()



window = MainWindow()
Gtk.main()

Solution

  • You want GtkPaned for this. Set the orientation to GTK_ORIENTATION_VERTICAL for a vertical one, put the text editor scrolled window in the first slot (gtk_paned_add1), and the terminal scrolled window in the second slot (gtk_paned_add2).