I can't figure out how to use wxpython's BoxSizer

122 Views Asked by At

I'm trying to learn how to use wxpython, but I can't seem to get the BoxSizer to work correctly. I've been at this for a while and looking at whatever documentation I can find, but I can't seem to find what I'm doing wrong.

Whenever I run the following code, it seems like the BoxSizer just doesn't do anything at all: https://i.stack.imgur.com/aLVAH.jpg

import wx

class Main(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, wx.ID_ANY, title="PictoCrypt", size=(-1,-1))

        # Initialize Panel
        self.panel = wx.Panel(self, wx.ID_ANY)

        #Encrypt & Decrypt radio buttons
        radioChoices = ["Encrypt", "Decrypt"]
        optionsBox = wx.RadioBox(self, id=wx.ID_ANY, choices=radioChoices, style=wx.RA_SPECIFY_COLS)

        #Path Entry Line
        pathLabel = wx.StaticText(self.panel, label="File:")
        pathEntry = wx.TextCtrl(self.panel)

        #Add Entry Line into Sizers
        pathSizer = wx.BoxSizer(wx.HORIZONTAL)
        pathSizer.Add(pathLabel, wx.SizerFlags().Left())
        pathSizer.Add(pathEntry, wx.SizerFlags().Right())

        #Add everything into main sizer
        self.topSizer = wx.BoxSizer(wx.VERTICAL)
        self.panel.SetSizer(self.topSizer)
        self.topSizer.Add(optionsBox)
        self.topSizer.Add(pathSizer)    

        self.Show(True)

app = wx.App(False)
frame = Main(None)
app.MainLoop()
1

There are 1 best solutions below

0
On

I think there's a mistake in this line:

optionsBox = wx.RadioBox(self.panel, id=wx.ID_ANY, choices=radioChoices, style=wx.RA_SPECIFY_COLS)

The parent of the RadioBox should be self.panel (not self).