newbie doubt about MVC,tkinter

gordon nodrogbrown at gmail.com
Wed Aug 27 03:32:50 EDT 2008


hi
i am trying to write a controller that creates a Tkinter gui,takes
userevents from gui and calls another program to do some calculation
and finally returns the results to gui to be displayed.

I tried to separate these three like MVC pattern
however ,being a newbie i have some doubts

sample gui class

class MyGUI:
    def __init__(self, parent):
         self.controller=MyController()
         self.myParent = parent
         self.mainframe = Frame(parent,background="grey")
         self.mainframe.pack(fill=BOTH,expand=YES)
         ...

        def button1Click(self):
             controller.callback(uservalue)

        def showResult(resultvalue):
             //display on canvas


class MyController:
     def createGUI(self):
        root = Tk()
        root.wm_title("MyGUI")
        self.myapp = MyGUI(root)
        root.mainloop()

    def callback(value):
       self.userenteredvalue=value
    def callGUI(self,resultvalue):
        self.myapp.showResult(resultvalue)

if __name__ == "__main__":
    controller=MyController()
    controller.createGUI()
    resultTodisplay=self.userenteredvalue+1000 # or may be call some
program to do the calc
    controller.callGUI(resultTodisplay)

Here,root.mainloop() causes the application to go into Tk event loop
and the controller will not be able to interact with the gui until   i
close the window.

I was wondering if i can keep the gui window open and at the same time
call the gui objects methods from my controller.If anyone can help/
advise please do
thanks
gordon



More information about the Python-list mailing list