gpt4 book ai didi

python - 为什么我应该制作多个wx.Panel?

转载 作者:太空宇宙 更新时间:2023-11-03 19:38:34 25 4
gpt4 key购买 nike

已关注 this tutorial在 WxPython 上,我注意到在“查找/替换对话框”示例中存在额外的面板,但它们似乎实际上并未执行任何操作。事实上,它们似乎使布局更加困惑(尽管这可能是我在某个地方犯的一些错误)例如,本教程有以下代码:

panel = wx.Panel(self, -1)

panel1 = wx.Panel(panel, -1)
grid1 = wx.GridSizer(2, 2)
grid1.Add(wx.StaticText(panel1, -1, 'Find: ', (5, 5)), 0, wx.ALIGN_CENTER_VERTICAL)
grid1.Add(wx.ComboBox(panel1, -1, size=(120, -1)))
grid1.Add(wx.StaticText(panel1, -1, 'Replace with: ', (5, 5)), 0, wx.ALIGN_CENTER_VERTICAL)
grid1.Add(wx.ComboBox(panel1, -1, size=(120, -1)))

panel1.SetSizer(grid1)
vbox.Add(panel1, 0, wx.BOTTOM | wx.TOP, 9)

为什么它不同于:

panel = wx.Panel(self, -1)

grid1 = wx.GridSizer(2, 2)
grid1.Add(wx.StaticText(panel, -1, 'Find: ', (5, 5)), 0, wx.ALIGN_CENTER_VERTICAL)
grid1.Add(wx.ComboBox(panel, -1, size=(120, -1)))
grid1.Add(wx.StaticText(panel, -1, 'Replace with: ', (5, 5)), 0, wx.ALIGN_CENTER_VERTICAL)
grid1.Add(wx.ComboBox(panel, -1, size=(120, -1)))

vbox.Add(grid1, 0, wx.BOTTOM | wx.TOP, 9)

请注意,我没有创建面板,只是将 grid1 直接添加到 vbox

最佳答案

我不确定。我已将示例重新编写为更少的代码,尽管它有点难以理解。我可以通过电子邮件将此建议发送给她。

import wx

class FindReplace(wx.Dialog):
def __init__(self, parent, id, title):
wx.Dialog.__init__(self, parent, id, title, size=(255, 365))

vbox_top = wx.BoxSizer(wx.VERTICAL)
vbox = wx.BoxSizer(wx.VERTICAL)

grid1 = wx.GridSizer(2, 2)
grid1.Add(wx.StaticText(self, -1, 'Find: ', (5, 5)), 0, wx.ALIGN_CENTER_VERTICAL)
grid1.Add(wx.ComboBox(self, -1, size=(120, -1)))
grid1.Add(wx.StaticText(self, -1, 'Replace with: ', (5, 5)), 0, wx.ALIGN_CENTER_VERTICAL)
grid1.Add(wx.ComboBox(self, -1, size=(120, -1)))


hbox2 = wx.BoxSizer(wx.HORIZONTAL)
sizer21 = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Direction'), orient=wx.VERTICAL)
sizer21.Add(wx.RadioButton(self, -1, 'Forward', style=wx.RB_GROUP))
sizer21.Add(wx.RadioButton(self, -1, 'Backward'))
hbox2.Add(sizer21, 1, wx.RIGHT, 5)

sizer22 = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Scope'), orient=wx.VERTICAL)
# we must define wx.RB_GROUP style, otherwise all 4 RadioButtons would be mutually exclusive
sizer22.Add(wx.RadioButton(self, -1, 'All', style=wx.RB_GROUP))
sizer22.Add(wx.RadioButton(self, -1, 'Selected Lines'))
hbox2.Add(sizer22, 1)


sizer3 = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Options'), orient=wx.VERTICAL)
vbox3 = wx.BoxSizer(wx.VERTICAL)
grid = wx.GridSizer(3, 2, 0, 5)
grid.Add(wx.CheckBox(self, -1, 'Case Sensitive'))
grid.Add(wx.CheckBox(self, -1, 'Wrap Search'))
grid.Add(wx.CheckBox(self, -1, 'Whole Word'))
grid.Add(wx.CheckBox(self, -1, 'Incremental'))
vbox3.Add(grid)
vbox3.Add(wx.CheckBox(self, -1, 'Regular expressions'))
sizer3.Add(vbox3, 0, wx.TOP, 4)


sizer4 = wx.GridSizer(2, 2, 2, 2)
sizer4.Add(wx.Button(self, -1, 'Find', size=(120, -1)))
sizer4.Add(wx.Button(self, -1, 'Replace/Find', size=(120, -1)))
sizer4.Add(wx.Button(self, -1, 'Replace', size=(120, -1)))
sizer4.Add(wx.Button(self, -1, 'Replace All', size=(120, -1)))

sizer5 = wx.BoxSizer(wx.HORIZONTAL)
sizer5.Add((191, -1), 1, wx.EXPAND | wx.ALIGN_RIGHT)
sizer5.Add(wx.Button(self, -1, 'Close', size=(50, -1)))


vbox.Add(grid1, 0, wx.BOTTOM | wx.TOP, 9)
vbox.Add(hbox2, 0, wx.BOTTOM, 9)
vbox.Add(sizer3, 0, wx.BOTTOM, 15)
vbox.Add(sizer4, 0, wx.BOTTOM, 9)
vbox.Add(sizer5, 1, wx.BOTTOM, 9)
vbox_top.Add(vbox, 1, wx.LEFT, 5)

self.SetSizer(vbox_top)
self.Centre()


app = wx.App(False)
d = FindReplace(None, -1, 'Find/Replace')
d.ShowModal()
d.Destroy()
app.MainLoop()

关于python - 为什么我应该制作多个wx.Panel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2075638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com