[[oktatas:programozás:python:wxpython_gui|< wxPython]] ====== wxPython osztály változatok ====== * **Szerző:** Sallai András * Copyright (c) Sallai András, 2020, 2021 * Licenc: GNU Free Documentation License 1.3 * Web: https://szit.hu ===== Minimális ===== 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ű ===== 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 ===== 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 ===== 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ó ===== 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()