Jumat, 10 Oktober 2025

WXPYTHON - SpacerExample

 




import wx


class SpacerExample(wx.Frame):

        def __init__(self):

            wx.Frame.__init__(self, None, title = "Spacer example", size = (350, 370))

            panel = wx.Panel(self)


            font = wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL, False, "Mangal")

            title = wx.StaticText(panel, label = "Border using sizers", style = wx.ALIGN_CENTRE)

            title.SetFont(font)

            

            set1text = wx.StaticText(panel, label = "Please enter something")

            set1box = wx.TextCtrl(panel)


            set2text = wx.StaticText(panel , label = "Please enter something else")

            set2box = wx.TextCtrl(panel)


            set3text = wx.StaticText(panel, label = "Please enter something else again")

            set3box = wx.TextCtrl(panel)


            save = wx.Button(panel, label = "Save")

            cancel = wx.Button(panel, label = "Cancel")


            #these are my spaces in the main column

            topspace = wx.BoxSizer()

            vertspc1 = wx.BoxSizer()

            vertspc2 = wx.BoxSizer()

            vertspc3 = wx.BoxSizer()

            vertspc4 = wx.BoxSizer()

            vertspc5 = wx.BoxSizer()

            #these spacers are my right and left borders

            hzlspc1 = wx.BoxSizer()

            hzlspc2 = wx.BoxSizer()

            #this is the space between my buttons

            hzlspc3 = wx.BoxSizer()


            buttonarr = wx.BoxSizer()

            buttonarr.Add(cancel, proportion = 3, flag = wx.EXPAND)

            buttonarr.Add(hzlspc3, proportion = 1)

            buttonarr.Add(save, proportion = 3, flag = wx.EXPAND)

            #this organises the main column of my programme

            mainsizer = wx.BoxSizer(wx.VERTICAL)

            mainsizer.Add(topspace, proportion = 1)

            mainsizer.Add(title, proportion = 4, flag = wx.EXPAND)

            mainsizer.Add(vertspc1, proportion = 1)

            mainsizer.Add(set1text, proportion = 2)

            mainsizer.Add(set1box, proportion = 2, flag = wx.EXPAND)

            mainsizer.Add(vertspc2, proportion = 2)

            mainsizer.Add(set2text, proportion = 2)

            mainsizer.Add(set2box, proportion = 2, flag = wx.EXPAND)

            mainsizer.Add(vertspc3, proportion = 2)

            mainsizer.Add(set3text, proportion = 2)

            mainsizer.Add(set3box, proportion = 2, flag = wx.EXPAND)

            mainsizer.Add(vertspc4, proportion = 2)

            mainsizer.Add(buttonarr, proportion = 2, flag = wx.EXPAND)

            mainsizer.Add(vertspc5, proportion = 2)

            #this adds the left and right border

            layout = wx.BoxSizer()

            layout.Add(hzlspc1, proportion = 1)

            layout.Add(mainsizer, proportion = 8)

            layout.Add(hzlspc2, proportion = 1)

            #this sets the sizers in action, i only need to set the top one

            panel.SetSizer(layout)

            


app = wx.App(redirect=False)

window = SpacerExample()

window.Show()

app.MainLoop()

Tidak ada komentar: