[英]I can't figure out how to use wxpython's BoxSizer
I'm trying to learn how to use wxpython, but I can't seem to get the BoxSizer to work correctly. 我正在尝试学习如何使用wxpython,但是我似乎无法使BoxSizer正常工作。 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://imgur.com/a/ZRkjA 每当我运行以下代码时,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()
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
). RadioBox的父级应该是
self.panel
(而不是self
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.