2011-10-30 2 views
0

wxpythonに問題があります。次のコードを実行すると、リストボックスが小さなフォームで表示されます(リストボックスは約10x10で表示されます)。私はなぜこれが起こっているのか分かりませんし、オンラインでこれを手助けするリソースがあまりありません。私はボタンを追加しないと、リストボックスが正しく表示されます。私はそれが簡単な修正ですが、私は本当に困っています。私の問題が何かを理解できない場合は、次のコードを実行してください。wxpython、基本的なUIエラー、ボタンとリストボックスの競合?

import wx 

class MyFrame(wx.Frame): 
    """make a frame, inherits wx.Frame""" 
    def __init__(self,parent,id): 

     # create a frame, no parent, default to wxID_ANY 
     wx.Frame.__init__(self, parent, id, 'Testing', 
      pos=(300, 150), size=(600, 500)) 
     panel = wx.Panel(self) 
     sampleList = ['dsakdsko0', '1', '2', '3', '4'] 
     listBox = wx.ListBox(panel, -1, (4,3), (100, 60), sampleList, wx.LB_SINGLE) 
     listBox.SetSelection(3) 

     self.SetBackgroundColour("white") 

     wx.Button(self, 1, 'Close', (50, 130)) 
     wx.Button(self, 2, 'Random Move', (150, 130), (110, -1)) 

     self.Bind(wx.EVT_BUTTON, self.OnClose, id=1) 
     self.Bind(wx.EVT_BUTTON, self.OnRandomMove, id=2) 

     # show the frame 
     self.Show(True) 
     #menu bar 
     status=self.CreateStatusBar() 
     menubar=wx.MenuBar() 
     first=wx.Menu() 
     second=wx.Menu() 
     first.Append(wx.NewId(),"New","Creates A new file") 
     first.Append(wx.NewId(),"ADID","Yo") 
     menubar.Append(first,"File") 
     menubar.Append(second,"Edit") 
     self.SetMenuBar(menubar) 

    def OnClose(self, event): 
     self.Close(True) 

    def OnRandomMove(self, event): 
     screensize = wx.GetDisplaySize() 
     randx = random.randrange(0, screensize.x - APP_SIZE_X) 
     randy = random.randrange(0, screensize.y - APP_SIZE_Y) 
     self.Move((randx, randy)) 

if __name__=='__main__': 
    application = wx.PySimpleApp() 
    frame=MyFrame(parent=None,id=-1) 
    frame.Show() 
    # start the event loop 
    application.MainLoop() 

ありがとうございました。

答えて

0

問題は両親に関係します。あなたのボタンの親はフレームであり、リストボックスの親はパネルです。パネルを親としてボタンに付けてください。問題は消えてしまいます。ちなみに、自分のID番号を割り当てることは、通常はお勧めできません。特に低いID番号は、使用される可能性があるためです。しかし、あなたが本当にしたいのなら、Robin DunnのwxPythonの本からの指示に従います:

"wxPythonがグローバル関数wx.RegisterId()を呼び出すことによって、アプリケーション内のあなたの明示的なIDを使用しないようにすることができます。プログラムがwxPython のIDを複製するのではなく、グローバル定数wx.ID_LOWESTとwx.ID_HIGHESTの間でID番号を使用しないでください。

編集:ここでのソートの例です:

変更この:これに

wx.Button(self, 1, 'Close', (50, 130)) 
wx.Button(self, 2, 'Random Move', (150, 130), (110, -1)) 

wx.Button(panel, 1, 'Close', (50, 130)) 
wx.Button(panel, 2, 'Random Move', (150, 130), (110, -1)) 

その後、あなたのIDを登録するには:

個人的に
wx.RegisterId(1) 
wx.RegisterId(2) 

、私はちょうど私のbを作成するだろうこのようなuttonsは代わりに:

closeBtn = wx.Button(panel, wx.ID_ANY, 'Close', (50, 130)) 
self.Bind(wx.EVT_BUTTON, self.OnClose, closeBtn) 
randomBtn = wx.Button(panel, wx.ID_ANY, 'Random Move', (150, 130), (110, -1)) 
self.Bind(wx.EVT_BUTTON, self.OnRandomMove, randomBtn) 
+0

おかげで、しかし、私はまだこれに少し新しいです、あなたはそれが –

+0

おかげでロットをどのように行われるか私を見ることができます!!!! –

関連する問題