我试图学习如何使用wxpython,但我似乎无法使BoxSizer正常工作。我已经有一段时间了,看着我能找到的任何文件,但我似乎无法找到我做错的事。
每当我运行以下代码时,似乎BoxSizer根本不做任何事情: https://imgur.com/a/ZRkjA
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()
答案 0 :(得分:1)
我认为这一行有一个错误:
optionsBox = wx.RadioBox(self.panel, id=wx.ID_ANY, choices=radioChoices, style=wx.RA_SPECIFY_COLS)
RadioBox的父级应为self.panel
(不是self
)。