Tartalomjegyzék

< wxPython GUI

wxPython MVC

Ablak nyomógombbal

Könyvtárszerkezet

projekt01/
  |-controllers/
  |   `-main_controller.py
  |-models/
  |   `-main_model.py
  |-views/
  |   `-main_frame.py
  `-projekt01.py

UML diagram

Kód

projekt01/projekt01.py
import wx
from controllers.main_controller import MainController
 
class Prog01App(wx.App):
    def OnInit(self):
        MainController()
        return True
 
prog01 = Prog01App()
prog01.MainLoop()
projekt01/controllers/controller.py
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)
projekt01/views/main_frame.py
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")
projekt01/models/model.py
class MainModel:
    def get_name(self):
        return 'Nagy János'

Egyéb irodalom