tkinter canvas mvc

Discussion in 'Python' started by Gigs_, Apr 5, 2007.

  1. Gigs_

    Gigs_ Guest

    Hi all!

    I have just finished my tkinter text editor, learning tkinter purpose.

    Now I want to learn canvas so I want to make my paint program, I think that this
    will be the best to do over model-view-controler pattern which I need to learn also.

    Is there any good tutorial for mvc in python or can someone explain me little
    bit about mvc?
    or maybe some code snippet in mvc, that will be nice.

    Thanks in advance!
     
    Gigs_, Apr 5, 2007
    #1
    1. Advertising

  2. Gigs_

    James Stroud Guest

    Gigs_ wrote:
    > Hi all!
    >
    > I have just finished my tkinter text editor, learning tkinter purpose.
    >
    > Now I want to learn canvas so I want to make my paint program, I think
    > that this will be the best to do over model-view-controler pattern which
    > I need to learn also.
    >
    > Is there any good tutorial for mvc in python or can someone explain me
    > little bit about mvc?
    > or maybe some code snippet in mvc, that will be nice.
    >
    > Thanks in advance!
    >


    MVC in a nutshell.

    1. You need a model.
    2. You need a view.
    3. You need a controller.

    Lets see how they work together, using dictionary-like interfaces:


    class Model(dict): pass

    class View(object):
    def __init__(self, controller, keys):
    self.controller = controller
    self.widgets = {}
    for k in keys:
    w = make_a_widget(k)
    def _callback(w=w):
    v = w.get_value()
    self.controller[k] = v
    w.bind(SomeEvent, _callback)
    self.widgets[k] = w
    self.controller.register_view(self)
    def __setitem__(self, k, v):
    self.widgets[k].set_value(v)
    def __contains__(self, k):
    return k in self.widgets

    class Controller(object):
    def __init__(self, model):
    self.views = []
    self.data = model
    def register_view(self, aview):
    self.views.append(aview)
    def __setitem__(self, k, v):
    self.data[k] = v
    for aview in self.views:
    if k in aview:
    aview[k] = v
    def __getitem__(self, k):
    return self.data[k]
    def update(self, adict):
    self.data.update(adict)
    for k,v in adict.items():
    for aview in self.views:
    if k in aview:
    aview[k] = v



    James
     
    James Stroud, Apr 6, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Askari
    Replies:
    2
    Views:
    735
    Askari
    Aug 30, 2004
  2. PhilC
    Replies:
    2
    Views:
    923
    PhilC
    Oct 25, 2004
  3. rmn190
    Replies:
    2
    Views:
    2,466
    Arne Vajhøj
    Jan 10, 2008
  4. Paulo
    Replies:
    3
    Views:
    508
    Peter Bromberg [C# MVP]
    Dec 4, 2008
  5. Crazy Cat
    Replies:
    1
    Views:
    720
    schepp
    Sep 3, 2009
Loading...

Share This Page