2
我試圖尋找到的wxPython和施膠劑,我總結了以下例子:wxpython:嵌套的大小寫,並在左上角的小廣場?
import wx
class MyTestFrame(wx.Frame):
def __init__(self, parent, title):
super(MyTestFrame, self).__init__(parent, title=title,
size=(250, 150))
# the master panel of the frame - "Add a panel so it looks correct on all platforms"
self.panel = wx.Panel(self, wx.ID_ANY)
# self.panel.SetBackgroundColour(wx.Colour(124, 224, 124)) # to confirm the square is the panel
# want these buttons absolutely positioned
btn_A = wx.Button(self, id=1, label='A', pos=(10, 10), size=(30, 30))
btn_A.SetBackgroundColour(wx.Colour(224, 124, 124))
btn_B = wx.Button(self, id=2, label='B', pos=(45, 10), size=(30, 30))
btn_C = wx.Button(self, id=3, label='C', pos=(80, 10), size=(30, 30))
# additional object
mastersizer = wx.BoxSizer(wx.VERTICAL)
btnsizer = wx.BoxSizer(wx.HORIZONTAL)
btnsizer.Add(btn_A, 0)
btnsizer.Add(btn_B, 0)
btnsizer.Add(btn_C, 0)
mastersizer.Add(btnsizer, 1, wx.EXPAND)
self.panel.SetSizer(mastersizer)
#~ mastersizer.Fit(self) # makes the window as large as the buttons
self.Centre()
self.Show()
if __name__ == '__main__':
app = wx.App()
MyTestFrame(None, 'Test')
app.MainLoop()
當我運行它,我得到一個窗口像在圖像上:
有人可以解釋一下,爲什麼我會在左上角得到那個灰色的小方塊 - 以及實現代碼的正確方法是什麼? (該按鈕是故意着色的,所以它可能很明顯..)我在Ubuntu Lucid上,以防特定於平臺。
編輯︰該廣場顯然是面板本身,但然後我不能告訴爲什麼它不調整大小,成爲按鈕的'父',如預期的那樣?