2017-05-14 113 views
0

我想用wx.Dialog創建一個對話框。有關wx.Dialog的基本問題

我有兩個問題。

我是否必須將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作爲父母。這應該不會影響sizer的行爲。確保在關閉對話框後銷燬對話框,以防止出現孤立的對話框。