本文介绍了我如何用一个对话框启动一个 wxPython 程序,然后弹出另一个对话框,然后制作一个基本的画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
如何在wxPython中链接多个wx.Dialog
我想制作一个 wxPython 应用程序,它首先向我显示一个 messageDialog,然后是一个输入对话框(保存玩家名称),然后是一个 dc(DrawCanvas).
Hi I want to make a wxPython app which first shows me a messageDialog, then an input dialog (which saves the playerName) and then makes a dc (DrawCanvas).
请问any1可以为我设置这个框架吗?(我一直将面板与框架和对话框混在一起)
Can any1 set up this framework for me plz?(I keep mixing up panels with frames and dialogs)
推荐答案
我已经回答了这个问题,但这里又是我的答案:只需将对话框创建和实例化放在 Panel.init 和之前还要别的吗.这里也有一些示例代码:
I already answered this, but here's my answer again: just put the dialog creation and instantiation right after the Panel.init and before anything else. Here's some example code too:
import wx
########################################################################
class MyDlg(wx.Dialog):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Dialog.__init__(self, None, title="I'm a dialog!")
lbl = wx.StaticText(self, label="Hi from the panel's init!")
btn = wx.Button(self, id=wx.ID_OK, label="Close me")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(lbl, 0, wx.ALL, 5)
sizer.Add(btn, 0, wx.ALL, 5)
self.SetSizer(sizer)
########################################################################
class MyPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
# show a custom dialog
dlg = MyDlg()
dlg.ShowModal()
dlg.Destroy()
self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnPaint(self, evt):
pdc = wx.PaintDC(self)
try:
dc = wx.GCDC(pdc)
except:
dc = pdc
rect = wx.Rect(0,0, 100, 100)
for RGB, pos in [((178, 34, 34), ( 50, 90)),
(( 35, 142, 35), (110, 150)),
(( 0, 0, 139), (170, 90))
]:
r, g, b = RGB
penclr = wx.Colour(r, g, b, wx.ALPHA_OPAQUE)
brushclr = wx.Colour(r, g, b, 128) # half transparent
dc.SetPen(wx.Pen(penclr))
dc.SetBrush(wx.Brush(brushclr))
rect.SetPosition(pos)
dc.DrawRoundedRectangleRect(rect, 8)
########################################################################
class MyFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Example frame")
# show a MessageDialog
style = wx.OK|wx.ICON_INFORMATION
dlg = wx.MessageDialog(parent=None,
message="Hello from the frame's init",
caption="Information", style=style)
dlg.ShowModal()
dlg.Destroy()
# create panel
panel = MyPanel(self)
if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame()
frame.Show()
app.MainLoop()
这篇关于我如何用一个对话框启动一个 wxPython 程序,然后弹出另一个对话框,然后制作一个基本的画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!