我需要知道如何将MessageDialog放到我现有的帧上,而不是弹出框架。我尝试只为“确定”和“取消”制作按钮,但我无法弄清楚如何获得我在ok和取消之前的文本框的价值。我得到了TextCtrlInstance.GetValue() is not defined.
的错误这是简化的代码,我不会帮助它,但我会发布它。在这段代码中,弹出一个窗口,显示确定并取消,但我希望它在300 x 300帧中。
import wx
class oranges(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Stuff',size=(300,300))
panel = wx.Panel(self)
box = wx.MessageDialog(self, 'Cool','title',wx.OK|wx.CANCEL)
result=box.ShowModal()
if result==wx.ID_OK:
print 'ok'
if __name__=='__main__':
app=wx.PySimpleApp()
frame=oranges(parent=None,id=-1)
frame.Show()
app.MainLoop()
非常感谢!期待着答案!
答案 0 :(得分:1)
听起来你可能想要一个MDI窗口:
https://github.com/crankycoder/wxPython-2.9.2.4/blob/master/wxPython/demo/MDIWindows.py
http://wxpython.org/Phoenix/docs/html/MDIChildFrame.html
http://www.java2s.com/Tutorial/Python/0380__wxPython/MDIframe.htm
使用带有这些按钮和文本框的自定义面板会更容易,例如:
import wx
class modalPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1)
sizer = wx.BoxSizer(wx.HORIZONTAL)
self.okBtn = wx.Button(self, -1, "OK")
self.okBtn.Bind(wx.EVT_BUTTON, self.OnOkClick)
sizer.Add(self.okBtn, 0)
self.SetSizer(sizer)
def OnOkClick(self, event):
#do stuff
pass
self.Hide()
self.GetParent().GetParent().stuffPanel.Show()
class normalPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1)
sizer = wx.BoxSizer(wx.HORIZONTAL)
self.btn = wx.Button(self, -1, "Show Modal")
sizer.Add(self.btn, 0)
self.SetSizer(sizer)
class oranges(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1,'Stuff',size=(300,300))
self.panel = wx.Panel(self)
self.sizer = wx.BoxSizer(wx.HORIZONTAL)
self.stuffPanel = normalPanel(self.panel)
self.stuffPanel.btn.Bind(wx.EVT_BUTTON, self.OnBtn)
self.panel2 = modalPanel(self.panel)
self.panel2.Hide()
self.sizer.Add(self.stuffPanel, 0, wx.EXPAND)
self.sizer.Add(self.panel2, 0, wx.EXPAND)
self.panel.SetSizer(self.sizer)
def OnBtn(self, event):
self.stuffPanel.Hide()
self.panel2.Show()
self.sizer.Layout()
if __name__=='__main__':
app=wx.App(False)
frame=oranges()
frame.Show()
app.MainLoop()