2017-05-14 7 views
0

wx.Dialogを使ってダイアログを作成したいと思います。wx.Dialogについての基本的な質問

私には2つの質問があります。

親ウィンドウとしてwx.Frameを設定する必要がありますか、またはメインウィンドウとしてwx.Dialogを使用できますか?

Sizerは親なしのwx.Dialogで使用可能ですか?

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

答えて

1

ためにはありません、あなたはwx.Frameを設定する必要はありません
はい、あなたは自分自身でダイアログを使用することができます
はい、サイザーは、ここでの例ですダイアログ
で使用することができます。

#!/usr/bin/env python 
import wx 
class TestDialog(wx.Dialog): 
    def __init__(self, parent, msg, title): 
     wx.Dialog.__init__(self, parent, id=-1, title=title) 
     Buttons = [] 
     Buttons.append(wx.Button(self,1, "Approve Location")) 
     Buttons.append(wx.Button(self,2, "Approve Item")) 
     Buttons.append(wx.Button(self,3, "Change Qty")) 
     Buttons.append(wx.Button(self,4, "Approve")) 
     sizer = wx.GridBagSizer(5,3) 
     sizer.Add(Buttons[0], (0, 5), (1,1), wx.EXPAND) 
     sizer.Add(Buttons[1], (1, 4), (1,1), wx.EXPAND) 
     sizer.Add(Buttons[2], (1, 5), (1,1), wx.EXPAND) 
     sizer.Add(Buttons[3], (2, 5), (1,1), wx.EXPAND) 
     self.Bind(wx.EVT_BUTTON, self.OnLocation, id=1) 
     self.Bind(wx.EVT_BUTTON, self.OnItem, id=2) 
     self.Bind(wx.EVT_BUTTON, self.OnQty, id=3) 
     self.Bind(wx.EVT_BUTTON, self.OnApprove, id=4) 
     self.buttonpressed = None 
     self.SetSizerAndFit(sizer) 
     self.Centre() 
    def OnLocation(self,event): 
     self.EndModal(1) 
     self.buttonpressed="Location" 
    def OnItem(self,event): 
     self.EndModal(2) 
     self.buttonpressed="Item" 
    def OnQty(self,event): 
     self.EndModal(3) 
     self.buttonpressed="Qty" 
    def OnApprove(self,event): 
     self.EndModal(4) 
     self.buttonpressed="Approve" 

if __name__ == "__main__": 
    app = wx.App() 
    dlg = TestDialog(None, "test my dialog", "Test Title") 
    val = dlg.ShowModal() 
    print "Dialog numeric result: " + str(val) 
    print "Dialog text: " + str(dlg.buttonpressed) 
0

はいできます。 Noneを親として渡します。これはサイザーの動作に影響を与えません。孤立したダイアログを防ぐために、閉じた後にダイアログを破棄してください。