0
wxPythonの学習中にMVCパターンを学習しようとしています。私は画像の配列からランダムな画像を表示しようとしていますが、ここからどこに行くのか分かりません。私はモデルやコントローラーに入っているかどうかわからないので、配列部分を除外しました。私が見つけたチュートリアルでは、私が何をしようとしているのかを簡単に説明することはできません。これの最も重要な部分は、この例を使用してMVCがどのように動作するかを理解したいと思っています。wxPython MVCパターンを使用して画像の配列からランダムな画像を表示する
#!/usr/bin/python3
# import statements
import wx
import random
# define GUI class
class ViewFrame(wx.Frame): # view
# default constructor
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Display Random Image', size=(600, 400))
# create a new panel
panel=wx.Panel(self)
# create status bar
statusBar=self.CreateStatusBar()
# create an event handler object
self.eventHandler = EventHandler()
# TODO: create a location for a PNG file from the image[i] array
# create button
button = wx.Button(panel, id=wx.ID_ANY, label="Change Image")
button.Bind(wx.EVT_BUTTON, self.eventHandler.onButton)
# end __init__
# end ViewFrame class
#----------------------------------------------------------------------
# define event handler
class EventHandler(): # controller
self.action = Action()
# define a button action method
def onButton(self, event):
self.action.change()
# TODO: figure out how to take the random return value
# and display the image[i] to the view
#----------------------------------------------------------------------
class Action(): # model
def __init__(self, images = 5):
self.images = images
self.change()
def change(self):
self.value = random.randint(1, self.images)
return self.value
# end Action class
#---------------------------------------------------------------------
if __name__ == '__main__' :
app=wx.App()
frame=ViewFrame(parent=None, id=1)
frame.Show()
app.MainLoop()