2011-11-08 17 views
1

リストボックスの下にボタンを置こうとしていますが、試してみるとすべてが歪んでいるか、問題が発生しているようです。私は誰でも私を助けることを望んでいます。wxpythonのリストボックスの下にボタンを置く?

リストボックスの下に2つのボタンを置いて、ウィンドウのサイズに応じて位置を変更する必要があります(消滅しないように)。アプリのウィンドウのサイズを変更すると、ボタン。ここで

は私がこれまでに

things_inlistbox=[] 
things2_listbox=[] 
things3listbox=[] 
things4listbox=[] 
import wx 
def areachange(self,pg): 
    print pg 
    if pg=="Things": 
     self.Things_area.Show() 
    else: 
     self.Things_area.Hide() 

class things1tab(wx.Panel): 
    def newAddImage(self,parent): 
     things2_listbox.append('hi'); 
     self.listBox.Set(things2_listbox) 
     self.listBox.SetSelection(len(things2_listbox)-1) 
    def reName(self,parent): 
     sel = self.listBox.GetSelection() 
     text = self.listBox.GetString(sel) 
     renamed = wx.GetTextFromUser('Rename item', 'Rename dialog', text) 
     if renamed != '': 
      things2_listbox.pop(sel) 
      things2_listbox.insert(sel,renamed) 
      self.listBox.Set(things2_listbox) 
      self.listBox.SetSelection(sel) 
    def __init__(self, parent): 
     wx.Panel.__init__(self, parent) 
     self.listBox = wx.ListBox(self, size=(200, -1), choices=things2_listbox, style=wx.LB_SINGLE) 
     self.sizer = wx.BoxSizer() 
     self.sizerMain = wx.BoxSizer() 
     self.listBox.Bind(wx.EVT_LISTBOX_DCLICK, self.reName) 

     self.sizer.Add(self.listBox, proportion=0, flag=wx.TOP | wx.EXPAND | wx.LEFT, border=5) 
     self.sizerMain.Add(self.sizer, proportion=0, flag=wx.BOTTOM | wx.EXPAND, border=70) 
     self.SetSizer(self.sizerMain) 
class imageArea(wx.Frame): 
    def __init__(self, parent): 
     wx.Frame.__init__(self, parent) 
     wx.StaticBox(self, -1, 'Personal Info', (400, 5), size=(240, 170)) 
     self.quote = wx.StaticText(self, label="Your quote :", pos=(20, 30), size=(200, -1)) 
     self.Show() 

     self.SetSizer(self.sizerMain) 
class things2tab(wx.Panel): 
    def __init__(self, parent): 
     wx.Panel.__init__(self, parent) 
     t = wx.StaticText(self, -1, "This is a PageTwo object", (40,40)) 

class things3tab(wx.Panel): 
    def __init__(self, parent): 
     wx.Panel.__init__(self, parent) 
     t = wx.StaticText(self, -1, "This is a PageThree object", (60,60)) 

class things4tab(wx.Panel): 
    def __init__(self, parent): 
     wx.Panel.__init__(self, parent) 
     t = wx.StaticText(self, -1, "This is a PageThree object", (400,60)) 

class MyNotebook(wx.Notebook): 
    def __init__(self, *args, **kwargs): 
     wx.Notebook.__init__(self, *args, **kwargs) 

class MyPanel(wx.Panel): 
    def OnPageChanged(self, event): 
     new = event.GetSelection() 
     areachange(self,self.notebook.GetPageText(new)) 
     event.Skip() 

    def OnPageChanging(self, event): 
     event.Skip() 
    def __init__(self, *args, **kwargs): 
     wx.Panel.__init__(self, *args, **kwargs) 
     self.notebook = MyNotebook(self, size=(225, -1)) 
#  self.button = wx.Button(self, label="Something else here? Maybe!") 
     tab_Things = things1tab(self.notebook) 
     tab_Things2 = things2tab(self.notebook) 
     tab_Things3 = things3tab(self.notebook) 
     tab_Things4 = things4tab(self.notebook) 

     # add the pages to the notebook with the label to show on the tab 
     self.notebook.AddPage(tab_Things, "Things",select=True) 
     self.notebook.AddPage(tab_Things2, "Things2") 
     self.notebook.AddPage(tab_Things3, "Things3") 
     self.notebook.AddPage(tab_Things4, "Things4") 
     self.Things_area=wx.StaticText(self, -1, "This is a PageOne object", (300,240)) 
     self.sizer = wx.BoxSizer() 
     self.sizer.Add(self.notebook, proportion=0, flag=wx.EXPAND) 
#  self.sizer.Add(self.button, proportion=0) 
     self.SetSizer(self.sizer) 
     self.notebook.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged) 
     self.notebook.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.OnPageChanging) 
     areachange(self,self.notebook.GetPageText(0))   


class MainWindow(wx.Frame): 
    def __init__(self, *args, **kwargs): 
     wx.Frame.__init__(self, *args, **kwargs) 
     self.panel = MyPanel(self) 

     self.Show() 


app = wx.App(False) 
win = MainWindow(None, size=(600, 400)) 
app.MainLoop() 

私は誰もがそれを大幅にappiecatedされるだろう私を助けることができれば、これを行う方法を確認していない持っているものです。これが何か簡単なのであれば、私を許してください。しかし、私はこれを数日間はやめました。

答えて

1

私はこれがあなたが何を意味するかであるかないかどうかわからないんだけど、これであなたの「things1tab」のコードを交換してみてください、それが動作するかどうかを確認:私は

class things1tab(wx.Panel): 
    def newAddImage(self,parent): 
     things2_listbox.append('hi'); 
     self.listBox.Set(things2_listbox) 
     self.listBox.SetSelection(len(things2_listbox)-1) 
    def reName(self,parent): 
     sel = self.listBox.GetSelection() 
     text = self.listBox.GetString(sel) 
     renamed = wx.GetTextFromUser('Rename item', 'Rename dialog', text) 
     if renamed != '': 
      things2_listbox.pop(sel) 
      things2_listbox.insert(sel,renamed) 
      self.listBox.Set(things2_listbox) 
      self.listBox.SetSelection(sel) 
    def __init__(self, parent): 
     wx.Panel.__init__(self, parent) 
     self.listBox = wx.ListBox(self, size=(200, -1), choices=things2_listbox, style=wx.LB_SINGLE) 
     self.sizer = wx.BoxSizer(wx.VERTICAL) 
     btnSizer = wx.BoxSizer(wx.HORIZONTAL) 
     self.sizerMain = wx.BoxSizer() 
     self.listBox.Bind(wx.EVT_LISTBOX_DCLICK, self.reName) 
     btn = wx.Button(self, label="Test") 
     btnTwo = wx.Button(self, label="Test 2") 

     self.sizer.Add(self.listBox, proportion=1, flag=wx.TOP | wx.EXPAND | wx.LEFT, border=5) 
     btnSizer.Add(btn, 0, wx.ALL, 5) 
     btnSizer.Add(btnTwo, 0, wx.ALL, 5) 
     self.sizer.Add(btnSizer) 
     self.sizerMain.Add(self.sizer, proportion=0, flag=wx.BOTTOM | wx.EXPAND, border=70) 
     self.SetSizer(self.sizerMain) 

すべてのボタンサイザーを作成し、それに2つのボタンを追加し、あなたの "self.sizer"の中に入れ子にします。私はまた、次の比率を0から1に変更しました:

self.sizer.Add(self.listBox, proportion=1, flag=wx.TOP | wx.EXPAND | wx.LEFT, border=5) 

これはあなたがもっと遠くに行くのを助けてくれることを願っています。

+1

ウィジェット検査ツールも便利です:http://wiki.wxpython.org/Widget%20Inspection%20Tool –

+0

Excellent !!!ありがとうございました! –

+0

私はサイザーで多くの問題を抱えています –

関連する問題