2
我想創建某種日誌框來流化python應用程序的控制檯輸出。響應StaticBox?
爲了在用戶界面內更好的出現,我想將TextCtrl
放入StaticBox
,理想情況下在用戶調整主框架時將其展開。我已經嘗試添加GridBagSizer
,它允許使用AddGrowableCol(index)
和AddGrowableRow(index)
方法。然而讓行「可增長」有沒有影響,這是只是在一瞬間水平工作:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
class Example(wx.Frame):
def __init__(self, parent, title):
super(Example, self).__init__(parent, title=title,
size=(450, 350))
self.InitUI()
self.Centre()
self.Show()
def InitUI(self):
self.main_sizer = wx.GridBagSizer(5, 5)
# Create the grouping box and sizer for the outline
self.box = wx.StaticBox(self, -1, "Logging")
self.bsizer = wx.StaticBoxSizer(self.box, wx.VERTICAL)
# Create the sizer and place controls within box
self.gbs = wx.GridBagSizer(5,5)
self.log_ctrl = wx.TextCtrl(self, size=(-1, 200), style=wx.TE_MULTILINE|wx.VSCROLL)
self.gbs.Add(self.log_ctrl, (0,0), flag=wx.EXPAND|wx.ALL, border=10)
# Place the control inside group box
self.bsizer.Add(self.gbs, flag=wx.EXPAND)
self.gbs.AddGrowableCol(0)
# Adding to the main sizer
self.main_sizer.Add(self.bsizer, pos=(0, 0), span=(1, 30), flag=wx.EXPAND|wx.BOTTOM)
self.main_sizer.AddGrowableCol(0)
# Place the static group box sizer within the border frame
# Creating a border that the static box will sit inside
self.border = wx.BoxSizer()
self.border.Add(self.main_sizer, 1000, wx.ALL, 15)
self.SetSizerAndFit(self.border)
if __name__ == '__main__':
app = wx.App()
Example(None, title="Example")
app.MainLoop()
問:是否有添加wx.TextCtrl
元素爲wx.StaticBox
的任何巧妙的方式爲了填充主窗口垂直以及橫向什麼時候展開呢?
輝煌,感謝彼得! – p2or