I have been trying to make a simple Gtk application that includes a Side Bar similar to the side bar in the Lollypop music player (as seen here https://youtu.be/2IhJCrKz3N4 ), I don't which layout container is the best for such a thing , I tried Gtk.Box with vertical orientation but the result similar to what I want. can someone suggest a better solution for this and a way to place this side bar on the window while keeping it's side fixed.
For new developer it may be difficult to dig into source code of some software, but it is really helps you in long run. Please check out source code of Lollypop at https://gitlab.gnome.org/World/lollypop for functionality you are taking about.
Apart from that, in below code I try to give you head start from what I understood from your question.
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class MyWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Side Bar")
self.hbox = Gtk.HBox();
self.vbox = Gtk.VBox();
self.button1 = Gtk.Button(label="1")
self.button1.connect("clicked", self.on_button_clicked)
self.button2 = Gtk.Button(label="2")
self.button2.connect("clicked", self.on_button_clicked)
self.button3 = Gtk.Button(label="3")
self.button3.connect("clicked", self.on_button_clicked)
self.button4 = Gtk.Button(label="4")
self.button4.connect("clicked", self.on_button_clicked)
self.vbox.add(self.button1);
self.vbox.add(self.button2);
self.vbox.add(self.button3);
self.vbox.add(self.button4);
self.entry = Gtk.Entry();
self.entry.set_text("1");
self.hbox.add(self.vbox);
self.hbox.add(self.entry);
self.add(self.hbox);
self.maximize()
def on_button_clicked(self, widget):
self.entry.set_text(widget.get_label());
win = MyWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()
Implementation of Lollypop may be very different from above one, because it may need to handle many more things like responsive size of button while resizing, look and feel with different themes, etc.
ADVISE: Keep digging and contributing to open source software to learn more.