[[oktatas:programozás:python:wxpython_gui|< wxPython GUI]]
====== wxPython MVC ======
* **Szerző:** Sallai András
* Copyright (c) Sallai András, 2020
* Licenc: [[https://creativecommons.org/licenses/by-sa/4.0/|CC Attribution-Share Alike 4.0 International]]
* Web: https://szit.hu
===== Ablak nyomógombbal =====
==== Könyvtárszerkezet ====
projekt01/
|-controllers/
| `-main_controller.py
|-models/
| `-main_model.py
|-views/
| `-main_frame.py
`-projekt01.py
==== UML diagram ====
{{:oktatas:programozas:python:wxpython_gui:mvc_osztalyok_wx.png|}}
==== Kód ====
import wx
from controllers.main_controller import MainController
class Prog01App(wx.App):
def OnInit(self):
MainController()
return True
prog01 = Prog01App()
prog01.MainLoop()
import wx
from views.main_frame import MainFrame
from models.main_model import MainModel
class MainController:
def __init__(self):
self.frame = MainFrame(None)
self.frame.Bind(wx.EVT_BUTTON,
self.on_click_button, self.frame.button)
self.main_model = MainModel()
self.frame.Show()
def on_click_button(self, event):
name = self.main_model.get_name();
self.frame.SetTitle(name)
import wx
class MainFrame(wx.Frame):
def __init__(self, parent):
super(MainFrame, self).__init__(parent)
self.SetSize((400, 300))
self.button = wx.Button(self, label="Mehet")
class MainModel:
def get_name(self):
return 'Nagy János'
===== Egyéb irodalom =====
* https://wiki.wxpython.org/ModelViewController (2020)