Felhasználói eszközök

Eszközök a webhelyen


oktatas:programozas:python:wxpython_gui:wxpython_koennyeden

< wxPython GUI

wxPython könnyedén

  • Szerző: Sallai András
  • Copyright © Sallai András, 2020
  • Licenc: GNU Free Documentation License 1.3

Kezdés

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

Konstruktor létrehozása

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

Két vezérlő elhelyezése

MainFrame.py
import wx
 
class MainFrame(wx.Frame):
    def __init__(self, parent):
        super(MainFrame, self).__init__(parent)
        self.button1 = wx.Button(self, label='Mehet')
        self.button1.SetPosition((50, 50))
        self.entry = wx.TextCtrl(self)
        self.entry.SetPosition((50, 100))
 
class App(wx.App):
    def OnInit(self):
        frame = MainFrame(None)
        frame.Show()
        return True
 
app = App()
app.MainLoop()

Eseménykezelés

MainFrame.py
import wx
 
class MainFrame(wx.Frame):
    def __init__(self, parent):
        super(MainFrame, self).__init__(parent)
        self.button1 = wx.Button(self, label='Mehet')
        self.button1.SetPosition((50, 50))
        self.Bind(wx.EVT_BUTTON, self.onClickGomb1, self.button1)
        self.entry = wx.TextCtrl(self)
        self.entry.SetPosition((50, 100))
    def onClickGomb1(self, event):
        print('Működik')
 
class App(wx.App):
    def OnInit(self):
        frame = MainFrame(None)
        frame.Show()
        return True
 
app = App()
app.MainLoop()

Az esemény fejlesztése

MainFrame.py
import wx
 
class MainFrame(wx.Frame):
    def __init__(self, parent):
        super(MainFrame, self).__init__(parent)
        self.button1 = wx.Button(self, label='vmi')
        self.button1.SetPosition((50, 50))
        self.Bind(wx.EVT_BUTTON, self.onClickGomb1, self.button1)
        self.entry = wx.TextCtrl(self)
        self.entry.SetPosition((50, 100))
    def onClickGomb1(self, event):
        numStr = self.entry.GetValue()
        product = int(numStr) * 2
        self.entry.SetValue(str(product))
 
class App(wx.App):
    def OnInit(self):
        frame = MainFrame(None)
        frame.Show()
        return True
 
app = App()
app.MainLoop()

InitUI létrehozása

MainFrame.py
import wx
 
class MainFrame(wx.Frame):
    def __init__(self, parent):
        super(MainFrame, self).__init__(parent)
        self.InitUI()
 
    def InitUI(self):
        self.button1 = wx.Button(self, label='vmi')
        self.button1.SetPosition((50, 50))
        self.Bind(wx.EVT_BUTTON, self.onClickGomb1, self.button1)
        self.entry = wx.TextCtrl(self)
        self.entry.SetPosition((50, 100))
 
    def onClickGomb1(self, event):
        numStr = self.entry.GetValue()
        product = int(numStr) * 2
        self.entry.SetValue(str(product))
 
class App(wx.App):
    def OnInit(self):
        frame = MainFrame(None)
        frame.Show()
        return True
 
app = App()
app.MainLoop()

Méretező használata

MainFrame.py
import wx
 
class MainFrame(wx.Frame):
    def __init__(self, parent):
        super(MainFrame, self).__init__(parent)
        self.InitUI()
        self.InitLayout()
 
    def InitUI(self):
        self.button1 = wx.Button(self, label='vmi')
        self.Bind(wx.EVT_BUTTON, self.onClickGomb1, self.button1)
        self.entry = wx.TextCtrl(self)
 
    def InitLayout(self):
        self.sizer1 = wx.BoxSizer(wx.VERTICAL)
        self.sizer1.Add(self.button1)
        self.sizer1.Add(self.entry)
        self.SetSizer(self.sizer1)
 
    def onClickGomb1(self, event):
        numStr = self.entry.GetValue()
        product = int(numStr) * 2
        self.entry.SetValue(str(product))
 
class App(wx.App):
    def OnInit(self):
        frame = MainFrame(None)
        frame.Show()
        return True
 
app = App()
app.MainLoop()

Szétválasztás

App.py
import wx
 
from views.MainFrame import MainFrame
from controllers.Controller import Controller
 
class App(wx.App):
    def OnInit(self):
        frame = MainFrame(None)
        frame.Show()
        Controller(frame)
        return True
 
app = App()
app.MainLoop()
views/MainFrame.py
import wx
 
class MainFrame(wx.Frame):
    def __init__(self, parent):
        super(MainFrame, self).__init__(parent)
        self.InitUI()
        self.InitLayout()
 
    def InitUI(self):
        self.button1 = wx.Button(self, label='vmi')
        self.entry = wx.TextCtrl(self)
 
    def InitLayout(self):
        self.sizer1 = wx.BoxSizer(wx.VERTICAL)
        self.sizer1.Add(self.button1)
        self.sizer1.Add(self.entry)
        self.SetSizer(self.sizer1)
controllers/Controller.py
import wx
from views.MainFrame import MainFrame
 
class Controller:
    def __init__(self, mainFrame: MainFrame):
        self.mainFrame = mainFrame
        self.mainFrame.Bind(wx.EVT_BUTTON, self.onClickGomb1, self.mainFrame.button1)
 
    def onClickGomb1(self, event):
        numStr = self.mainFrame.entry.GetValue()
        product = int(numStr) * 2
        self.mainFrame.entry.SetValue(str(product))
oktatas/programozas/python/wxpython_gui/wxpython_koennyeden.txt · Utolsó módosítás: 2021/03/15 10:56 szerkesztette: admin