我一直在wxpython中使用静态定位一段时间,但需要切换到使用sizer,但我无法掌握它。下面是我使用静态定位的应用程序的缩减版本。有人可以给我一些关于如何将此布局转换为使用sizer的指示。我还会附上一个屏幕抓取:
import wx
import wx.lib.agw.aui as aui
import wx.stc as stc
class MainWindow(wx.Frame):
def __init__(self, parent, id, title):
# Setup GUI...
wx.Frame.__init__(self, parent, id, title, size=(900, 740), style=wx.DEFAULT_FRAME_STYLE & ~ (wx.RESIZE_BORDER |
wx.RESIZE_BOX |
wx.MAXIMIZE_BOX))
style = aui.AUI_NB_DEFAULT_STYLE ^ aui.AUI_NB_CLOSE_ON_ACTIVE_TAB
self.tabbed = aui.AuiNotebook(self, agwStyle=style)
self.submissions = SubmissionPane(self.tabbed)
self.tabbed.AddPage(self.submissions, "Submit Job")
self.Centre()
self.Show()
class SubmissionPane(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
modeList = ['Verify Mode', 'Upload Mode']
self.rb = wx.RadioBox(
self, -1, "", (35, 2), wx.DefaultSize,
modeList, 2, wx.RA_SPECIFY_COLS
)
tvbox = wx.StaticBox(self, -1, '', pos=(290, 2), size=(335, 41))
wx.StaticText(self, -1, ' Job Title', (317, 12), style=wx.ALIGN_CENTRE)
self.cb1 = wx.CheckBox(self, pos=(306, 12))
self.cb1.SetValue(False)
self.txtTitle = wx.TextCtrl(self, size=(215, 25), pos=(395, 10), style= wx.SUNKEN_BORDER, value="Enter job title here")
wx.StaticText(self, -1, ""'Drag n Drop itmsp folder'"", pos=(35, 60), style=wx.ALIGN_CENTRE)
self.tc_files = wx.TextCtrl(self, wx.ID_ANY, pos=(38, 80), size=(585, 25))
self.buttonGo = wx.Button(self, -1, "Submit", pos=(625, 78))
self.buttonClose = wx.Button(self, -1, "Quit Application", pos=(370,615))
self.index = 0
self.log_text22 = wx.ListCtrl(self, -1, pos=(35, 135), size=(800,275),
style=wx.LC_REPORT | wx.BORDER_SUNKEN | wx.LC_SINGLE_SEL | wx.LC_VRULES | wx.LC_HRULES)
font = wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
self.log_text22.SetFont(font)
self.log_text22.InsertColumn(1, 'Job ID', width=50, format=wx.LIST_FORMAT_CENTRE)
self.log_text22.InsertColumn(2, 'Mode ', width=50, format=wx.LIST_FORMAT_CENTRE)
self.log_text22.InsertColumn(3, 'Title', width=183)
self.log_text22.InsertColumn(4, 'Package', width=227)
self.log_text22.InsertColumn(5, 'Submitted By', width=100)
self.log_text22.InsertColumn(6, 'Sumbit Time', width=85)
self.log_text22.InsertColumn(7, 'Process', width=50, format=wx.LIST_FORMAT_CENTRE)
self.log_text22.InsertColumn(8, 'Status ', width=50, format=wx.LIST_FORMAT_CENTRE)
self.running_log1 = wx.stc.StyledTextCtrl(self, -1, pos=(35, 420), size=(800,175))
self.running_log1.StyleSetFont(wx.stc.STC_STYLE_DEFAULT, font)
self.running_log1.SetMarginWidth(1, 0)
self.running_log1.StyleSetBackground(wx.stc.STC_STYLE_DEFAULT, (0,0,0))
self.running_log1.StyleClearAll()
self.running_log1.StyleSetForeground(wx.stc.STC_STYLE_DEFAULT, (0,255,0))
self.running_log1.StyleClearAll()
self.Show()
app = wx.App()
MainWindow(None, -1, 'Test App')
app.MainLoop()
答案 0 :(得分:1)
它仍然有点繁琐,但这是BoxSizer的:
import wx
class MainWindow(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(900, 600) )
SubmissionsPanel(self)
self.Show()
class SubmissionsPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
#Create some sizers:
main_sizer = wx.BoxSizer(wx.VERTICAL)
top_row_sizer = wx.BoxSizer(wx.HORIZONTAL);
radio_static_box = wx.StaticBox(self, label='') #You have to add this widget to parent BEFORE
#contained widgets otherwise buttons won't operate.
radio_static_box_sizer = wx.StaticBoxSizer(radio_static_box, wx.HORIZONTAL)
job_static_box = wx.StaticBox(self, label='') #You have to add this widget to parent BEFORE
#contained widgets otherwise buttons won't operate.
job_static_box_sizer = wx.StaticBoxSizer(job_static_box, wx.HORIZONTAL)
'''
radio_labels = ['Verify Mode', 'Upload Mode']
self.radio_box = wx.RadioBox(
self, -1, "",
choices=radio_labels,
)
'''
#I couldn't get the radio buttons inside a RadioBox to line up vertically
#with the checkbox, so I did the following:
radio1 = wx.RadioButton(self, label='Verify Mode', style=wx.RB_GROUP)
radio2 = wx.RadioButton(self, label='Upload Mode')
radio1.Bind(wx.EVT_RADIOBUTTON, self.on_radio_click)
radio2.Bind(wx.EVT_RADIOBUTTON, self.on_radio_click)
radio_static_box_sizer.Add(radio1, flag=wx.BOTTOM, border=4) #To make outline line up with the outline of checkbox,txtctrl
radio_static_box_sizer.Add(radio2, flag=wx.LEFT, border=10)
top_row_sizer.Add(radio_static_box_sizer, flag=wx.LEFT, border=10)
#Create Job Title widgets:
self.check_box = wx.CheckBox(self, label="Job Title")
self.check_box.SetValue(False)
self.check_box.Bind(wx.EVT_CHECKBOX, self.ShowOrHideTVTitle)
self.txtTitle = wx.TextCtrl(self, style=wx.SUNKEN_BORDER, value="Enter job title here...", size=(200, -1))
self.txtTitle.Show(False)
job_static_box_sizer.Add(self.check_box, flag=wx.LEFT, border=10)
job_static_box_sizer.Add(self.txtTitle, flag=wx.RESERVE_SPACE_EVEN_IF_HIDDEN | wx.LEFT, border=10)
top_row_sizer.Add(job_static_box_sizer, flag=wx.LEFT, border=10);
main_sizer.Add(top_row_sizer);
main_sizer.Add((-1, 20)) #Add 20 pixels of vertical space
#Drag n Drop widgets:
drag_drop_text = wx.StaticText(self, -1, 'Drag n Drop itmsp folder')
main_sizer.Add(drag_drop_text, flag=wx.LEFT, border=10)
main_sizer.Add((-1, 3)) #Add 3 pixels of vertical space
third_row_sizer = wx.BoxSizer(wx.HORIZONTAL);
self.tc_files = wx.TextCtrl(self, size=(375, 25))
self.buttonGo = wx.Button(self, label='Submit')
third_row_sizer.Add(self.tc_files, flag=wx.LEFT, border=10)
third_row_sizer.Add(self.buttonGo, flag=wx.LEFT, border=10)
main_sizer.Add(third_row_sizer)
#Create ListCtrl:
self.index = 0
self.log_text22 = wx.ListCtrl(self,size=(800,275),
style=wx.LC_REPORT | wx.BORDER_SUNKEN | wx.LC_SINGLE_SEL | wx.LC_VRULES | wx.LC_HRULES)
font = wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
self.log_text22.SetFont(font)
self.log_text22.InsertColumn(1, 'Job ID', width=50, format=wx.LIST_FORMAT_CENTRE)
self.log_text22.InsertColumn(2, 'Mode ', width=50, format=wx.LIST_FORMAT_CENTRE)
self.log_text22.InsertColumn(3, 'Title', width=183)
self.log_text22.InsertColumn(4, 'Package', width=227)
self.log_text22.InsertColumn(5, 'Submitted By', width=100)
self.log_text22.InsertColumn(6, 'Sumbit Time', width=85)
self.log_text22.InsertColumn(7, 'Process', width=50, format=wx.LIST_FORMAT_CENTRE)
self.log_text22.InsertColumn(8, 'Status ', width=50, format=wx.LIST_FORMAT_CENTRE)
main_sizer.Add((-1, 20)) #Add 20px of vertical space
list_sizer = wx.BoxSizer(wx.VERTICAL)
list_sizer.Add(self.log_text22, flag=wx.LEFT, border=10)
main_sizer.Add(list_sizer)
#Create Quit button:
list_sizer.Add((-1, 10)) #Add 15px of vertical space
self.buttonClose = wx.Button(self, -1, "Quit Application")
list_sizer.Add(self.buttonClose, flag=wx.ALIGN_CENTER | wx.TOP | wx.LEFT, border=10)
self.SetSizer(main_sizer)
def on_radio_click(self, evt):
print "You clicked?"
def ShowOrHideTVTitle(self, evt):
element = evt.GetEventObject()
isChecked = element.GetValue()
if isChecked:
self.txtTitle.Show(True)
self.txtTitle.SetFocus()
else:
self.txtTitle.Show(False)
self.tc_files.SetFocus()
def OnSubmit(self):
pass
def OnClose(self):
pass
def showLogFile(self):
pass
def right_click(self):
pass
app = wx.App(redirect=False) ##Instead of seeing just a window flash, show errors in terminal.
MainWindow(None, -1, 'Test App')
app.MainLoop()