WxTemplate

WIDGET :: BIND :: SIZER :: EVENT :: REDIRECT

wxtemplate.png
#!/usr/bin/env python

import wx

class Frame(wx.Frame):
    def __init__(self, parent, id, title, pos, size, style):
            wx.Frame.__init__(self, parent, id, title, pos, size, style)
            p = wx.Panel(self)
            p.SetBackgroundColour('Grey')

            #------------------- WIDGET --------------------
            st = wx.StaticText(p, -1, "project")
            st.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
          label = wx.StaticText(p, -1, "label")
            textctrl = wx.TextCtrl(p, -1, "");
            button = wx.Button(p, -1, "do something")

            #------------------- BIND --------------------
            self.Bind(wx.EVT_BUTTON, self.OnThisEvent, button)
            self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

        #------------------- SIZER --------------------
            ms = wx.BoxSizer(wx.VERTICAL)
            ms.Add(st, 0, wx.ALL, 5)
            ms.Add(wx.StaticLine(p), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)

            td1 = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
            td1.AddGrowableCol(1)
        td1.Add(label, 0, wx.EXPAND)
            td1.Add(textctrl, 0, wx.EXPAND)
            ms.Add(td1, 0, wx.EXPAND|wx.ALL, 10)

            tr = wx.BoxSizer(wx.HORIZONTAL)
            tr.Add(button)
            ms.Add(tr, 0, wx.CENTER, 10)

            p.SetSizer(ms)

        #------------------- EVENT --------------------
    def OnThisEvent(self, event):
        pass

    def OnCloseWindow(self, event):
        self.Destroy()

class App(wx.App):
    def __init__(self, redirect=True, filename="wxtemplate_logs.txt"):
        wx.App.__init__(self, redirect, filename)

    def OnInit(self):
        self.frame = Frame(parent=None, id=-1, title='WxTemplate', pos=wx.DefaultPosition, size=(400, 300), style=wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.CLOSE_BOX | wx.RESIZE_BORDER | wx.CAPTION | wx.SYSTEM_MENU)
        self.frame.Show()
        self.frame.Center()
        self.SetTopWindow(self.frame)
        return True

if __name__ == '__main__':
    app = App(redirect=True)
    fred = app.MainLoop()
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License