定製對話框

对话框dialog — 定制对话框custom dialogs

有两个简化对话框创建的方法. 它们都会返回一个特定的 sizer 对象.

CreateTextSizer(self, string message)
CreateButtonSizer(self, long flags)

CreateTextSizer() 方法创建出一个文本 sizer. 下面的例子中,我们通过添加一些按钮来演示这个方法.[more…]

#!/usr/bin/python
#coding=utf-8

#customdialog1.py

import wx

class MyDialog(wx.Dialog):
    def __init__(self, parent, id, title):
        wx.Dialog.__init__(self, parent, id, title, size=(350, 300))
        
        sizer = self.CreateTextSizer('我的按钮')
        sizer.Add(wx.Button(self, -1, '按钮1'), 0, wx.ALL, 5)
        sizer.Add(wx.Button(self, -1, '按钮2'), 0, wx.ALL, 5)
        sizer.Add(wx.Button(self, -1, '按钮3'), 0, wx.ALL, 5)
        sizer.Add(wx.Button(self, -1, '按钮4'), 0, wx.ALL | wx.ALIGN_CENTER, 5)
        sizer.Add(wx.Button(self, -1, '按钮5'), 0, wx.ALL | wx.EXPAND, 5)
        
        self.SetSizer(sizer)
        
class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(550, 500))
        
        panel = wx.Panel(self, -1)
        wx.Button(panel, 1, '展示定制对话框', (100, 100))
        self.Bind(wx.EVT_BUTTON, self.OnShowCustomDialog, id=1)
        
    def OnShowCustomDialog(self, event):
        dia = MyDialog(self, -1, '系列按钮')
        dia.ShowModal()
        dia.Destroy() 
  
class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, 'customdialog1.py')
        frame.Show(True)
        frame.Center()
        return True
    
app = MyApp(0)
app.MainLoop()

这里的 CreateButtonSizer() 方法创建出一行的按钮. 通过不同的标志,你可以指定相应的按钮类型. CreateButtonSizer() 方法有着以下可用的标志:

  • wx.OK
  • wx.CANCEL
  • wx.YES
  • wx.NO
  • wx.HELP
  • wx.NO_DEFAULT
#!/usr/bin/python
#coding=utf-8

#customdialog2.py

import wx

class MyDialog(wx.Dialog):
    def __init__(self, parent, id, title):
        wx.Dialog.__init__(self, parent, id, title)
        
        vbox = wx.BoxSizer(wx.VERTICAL)
        stline = wx.StaticText(self, 11, 'Disciplice ist Macht.')
        vbox.Add(stline, 1, wx.ALIGN_CENTER | wx.TOP, 45)
        sizer = self.CreateButtonSizer(wx.NO|wx.YES|wx.HELP)
        vbox.Add(sizer, 0, wx.ALIGN_CENTER)
        self.SetSizer(vbox)
        self.Bind(wx.EVT_BUTTON, self.OnYes, id=wx.ID_YES)
        
    def OnYes(self, event):
        self.Close()
        
class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)
        panel = wx.Panel(self, -1)
        wx.Button(panel, 1, '显示定制对话框', (50, 50))
        self.Bind(wx.EVT_BUTTON, self.OnShowCustomDialog, id=1)

    def OnShowCustomDialog(self, event):
        dia = MyDialog(self, -1, '')
        val = dia.ShowModal()
        dia.Destroy()
        
class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, 'customdialog2.py')
        frame.Show(True)
        frame.Center()
        return True
    
app = MyApp(0)
app.MainLoop()

请注意,wxPython 是不会考虑标志的顺序的.

sizer = self.CreateButtonSizer(wx.NO|wx.YES|wx.HELP)

三个按钮将依照相关用户界面标准确立的顺序创建.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值