wxpython初探

# -*- coding: utf-8 -*-

import wx


class MyFrame(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self,
                          parent,
                          id,
                          'baby',
                          size=(300, 200),
                          style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER ^ wx.MAXIMIZE_BOX)
        panel = wx.Panel(self)
        btn_close = wx.Button(panel, label='Exit', pos=(30, 50), size=(100, 50))
        self.Bind(wx.EVT_BUTTON, self.slot_btn_close, btn_close)
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

    def slot_btn_close(self, event):
        self.Close(True)

    def OnCloseWindow(self, event):
        dig =wx.MessageDialog(self, 'Are you sure to exit?', 'Exit', wx.YES_NO | wx.ICON_QUESTION)
        reply = dig.ShowModal()
        if reply == wx.ID_YES:
            self.Destroy()
        else:
            pass


def main():
    app = wx.App()
    frame = MyFrame(parent=None, id=-1)
    frame.Show()
    app.MainLoop()


if __name__ == '__main__':
    main()

其中 style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER ^ wx.MAXIMIZE_BOX 可让窗口无法最大化同时无法拉伸。

 

你可能感兴趣的:(python)