> You will need to create a module that draws the GUI and >> handles the user events. That module will probably >> import this one (rather than this one importing Tkinter) >> You can then just pass the canvas object to each object >> in your environment and ask it to draw itself... > > You might like to separate your objects into model and >> view representations but thats getting into more advanced >> GUI design and probably not needed here. > > Can you advise me some links on examples of realization of this two > different approaches? Some tutorials would really help me :)
For a quick overview of Model/View (and sometimes Controller) take a look at the Apple web site. their default GUI design uses the paradigm and there is a good visual description in the overview: http://developer.apple.com/documentation/Cocoa/Conceptual/ObjCTutorial/chapter02/chapter_2_section_3.html For a slightly different approach try: http://www.mimuw.edu.pl/~sl/teaching/00_01/Delfin_EC/Overviews/ModelViewPresenter.htm For an example of the first approach I'll create a list of Characters (an environment of objects if you like?) And I'll arbitrarily modify them between button presses and get them to present themselves on each button press.... from Tkinter import * class Char: def __init__(self,c=''): self.c = c def display(self, aLabel): aLabel['text'] += self.c env = [Char(i) for i in 'abcdefgh'] # create an event handler def show(): lMessage['text'] = '' # reset text for c in env: c.display(lMessage) env.reverse() # change for next time # now create GUI top = Tk() F = Frame(top) F.pack() # add the widgets lMessage = Label(F, text="") lMessage.pack() bQuit = Button(F, text="Display", command=show) bQuit.pack() # set the loop running top.mainloop() _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor