Tartalomjegyzék

< wxPython

wxPython osztály változatok

Minimális

main.py
import wx
 
class MainFrame(wx.Frame):
    pass
 
 
class SimpleApp(wx.App):
    def OnInit(self):
        frame = MainFrame(None)
        frame.Show()
        return True
 
app = SimpleApp()
app.MainLoop()

Egyszerű

gomb.py
import wx
 
class MainFrame(wx.Frame):
    def __init__(self, parent):
        super(MainFrame, self).__init__(parent)
 
class SimpleApp(wx.App):
    def OnInit(self):
        frame = MainFrame(None)
        frame.Show()
        return True
 
app = SimpleApp()
app.MainLoop()

Szuper metódus hívása

import wx
 
class MainFrame(wx.Frame):
    def __init__(self, parent, title):
        super(MainFrame, self).__init__(parent, title=title)
 
app = wx.App()
frame = MainFrame(None, 'Valami')
frame.Show()
app.MainLoop()

Méret

import wx
 
class MainFrame(wx.Frame):
    def __init__(self, parent, title):
        super(MainFrame, self).__init__(parent, title=title, size=(800,600))
 
app = wx.App()
frame = MainFrame(None, 'Valami')
frame.Show()
app.MainLoop()

Stílus beállítással

frame02.py
import wx
 
class MainFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
 
class SimpleApp(wx.App):
    def OnInit(self):
        self.frame = MainFrame(None, wx.ID_ANY, "")
        self.SetTopWindow(self.frame)
        self.frame.Show()
        return True
 
 
 
if __name__ == "__main__":
    app = SimpleApp(0)
    app.MainLoop()

Ideális

frame01.py
import wx
 
class MainFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        wx.Frame.__init__(self, *args, **kwds)
 
class SimpleApp(wx.App):
    def OnInit(self):
        self.frame = MainFrame(None, wx.ID_ANY, "")
        self.SetTopWindow(self.frame)
        self.frame.Show()
        return True
 
 
 
if __name__ == "__main__":
    app = SimpleApp(0)
    app.MainLoop()

Ideális bővített verzió

frame01.py
import wx
 
class MainFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        wx.Frame.__init__(self, *args, **kwds)
        self.init_frame()
        self.set_layout()
 
    def init_frame(self): 
        #komponensek beállítása
 
        self.SetTitle("Program01")
        self.Centre()
 
    def set_layout(self):
        #layout
 
        main_box = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(main_box)
        self.Layout()
 
class SimpleApp(wx.App):
    def OnInit(self):
        self.frame = MainFrame(None, wx.ID_ANY, "")
        self.SetTopWindow(self.frame)
        self.frame.Show()
        return True
 
 
if __name__ == "__main__":
    app = SimpleApp(0)
    app.MainLoop()

Az init_frame helyett lehet InitUI()