What I'm aiming to do is build a 3x2 grid from within Python Gtk using the FlowBox widget.
The screenshot shows I'm doing the 3x2 perfectly. The problem is that I wanted the buttons to look like smaller squares and not fill up the whole screen. I realize I might have to do this with the grid layout, but I'm just hoping that this wouldve been accomplishable using FlowBox for simplicity. Any ideas?
from gi.repository import Gtk
class MyWindow(Gtk.Window):
def __init__(self):
super().__init__(title="Hello World")
self.box1 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.add(self.box1)
self.set_default_size(800, 500);
self.btnTL= Gtk.Button(label="back")
self.heading= Gtk.Label(label="Home")
self.btnTR= Gtk.Button(label="home")
self.boxT = Gtk.Box()
self.boxT.pack_start(self.btnTL, False, False, 0)
self.boxT.pack_start(self.heading,True, True, 0)
self.boxT.pack_start(self.btnTR, False, False, 0)
self.box1.add(self.boxT)
self.cFlow = Gtk.FlowBox()
self.cFlow.set_valign(Gtk.Align.FILL)
self.cFlow.set_max_children_per_line(3)
self.cFlow.set_hadjustment(Gtk.Adjustment(100, 100, 10, 100, 100, 100))
self.buttonAdd(self.cFlow)
self.buttonAdd(self.cFlow)
self.buttonAdd(self.cFlow)
self.buttonAdd(self.cFlow)
self.buttonAdd(self.cFlow)
self.buttonAdd(self.cFlow)
self.box1.pack_start(self.cFlow,True,True,0)
self.button1 = Gtk.Button(label="test")
self.button1.connect("clicked", self.on_button1_clicked)
#self.box1.pack_start(self.button1, True, True, 0)
self.btnBL = Gtk.Button(label="L")
self.bread = Gtk.Label(label="")
self.btnBR = Gtk.Button(label="R")
self.boxB = Gtk.Box()
self.boxB.pack_start(self.btnBL, False, False, 0)
self.boxB.pack_start(self.bread, True, True, 0)
self.boxB.pack_start(self.btnBR, False, False, 0)
self.box1.add(self.boxB)
UPDATE: I made some tweaks but now I get this issue where my window height expands from what I originally set it and I tried everything to eliminate the Xtra space. the window also expands when I add like an 8 character (or more) label to the button.
def buttonAdd(self,widget):
self.button2 = Gtk.Button("tffkjdsljdsflkds\nt")
#self.button2.set_halign(Gtk.Align.CENTER)
#self.button2.set_valign(Gtk.Align.CENTER)
#self.button2.set_vexpand(True)
#self.button2.set_hexpand(True)
#self.button2.set_property("height-request",100)
#self.button2.set_property("width-request",150)
self.button2.connect("clicked",self.clickedTest)
widget.add(self.button2)


