I’ve been battling creating a Frame that uses a GridBagSizer where I change the font on the elements to be large via
self.fbig = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT).MakeBold().Scale(4.)
The window is never large enough to show all the elements. Using just the system font it appears ok.
The large font screenshot
vs system font
My sample code to create this:
import string
import random
import wx
alpha = string.ascii_uppercase
def floatstr():
return f'{random.random() * 5:.6f}'
class MyP(wx.Panel):
def __init__(self, parent):
super().__init__(parent, wx.ID_ANY, pos=wx.DefaultPosition, style=wx.TAB_TRAVERSAL, name="MyP")
self.fbig = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT).MakeBold().Scale(4.)
# self.fbig = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT)
self.gbs = wx.GridBagSizer(5, 5)
self.gbs.SetEmptyCellSize((0, 0))
for row in range(5):
col = 0
lbl = f'row {row} col {col} {alpha[row::6]}' # make a longer label
b = wx.Button(self, label=lbl)
b.SetFont(self.fbig)
self.gbs.Add(b, pos=(row, col), flag=wx.EXPAND | wx.ALIGN_LEFT)
# two textctrl's holding floats
for _ in range(2):
col += 1
atxt = wx.TextCtrl(self, value=floatstr(), style=wx.TE_READONLY)
atxt.SetFont(self.fbig)
sz_x, _ = atxt.GetSizeFromTextSize(atxt.GetTextExtent('9' * 8))
atxt.SetInitialSize((sz_x, -1))
self.gbs.Add(atxt, pos=(row, col), flag=wx.ALIGN_RIGHT | wx.EXPAND)
# textctrl holding string
col += 1
stxt = f'{alpha[row + 3::6]}'
ut = wx.TextCtrl(self, value=stxt, style=wx.BORDER_NONE | wx.TE_READONLY)
sz_x, _ = ut.GetTextExtent(stxt)
ut.SetMinSize((sz_x, -1))
self.gbs.Add(ut, pos=(row, col), flag=wx.EXPAND | wx.ALIGN_LEFT)
# per an example, tried this too but no change
# flags = wx.SizerFlags(proportion=1).Expand().Border(wx.ALL, 10)
# box = wx.BoxSizer()
# box.Add(self.gbs, flags)
# self.SetSizer(box)
self.SetSizer(self.gbs)
self.Layout()
class MyF(wx.Frame):
def __init__(self, title):
super().__init__(parent=None, title=title)
panel = wx.Panel(self, style=wx.TAB_TRAVERSAL | wx.BORDER_DOUBLE)
vsizer = wx.BoxSizer(wx.VERTICAL)
myp = MyP(panel)
vsizer.Add(myp, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
my_btn = wx.Button(panel, label='Press Me')
vsizer.Add(my_btn, 0, wx.ALL | wx.CENTER, 5)
panel.SetSizerAndFit(vsizer)
self.SetClientSize(panel.GetSize())
self.Layout()
self.Show()
if __name__ == '__main__':
app = wx.App()
MyF(title='A Frame')
app.MainLoop()
This happens to be on a RHEL 8 computer with gtk, python 3.9.
I’ve tried lots of different things, so clearly I’m missing something critical. Ideas?
T.