newbie doubt about MVC,tkinter

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gordon

    #1

    newbie doubt about MVC,tkinter

    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,ba ckground="grey" )
    self.mainframe. pack(fill=BOTH, expand=YES)
    ...

    def button1Click(se lf):
    controller.call back(uservalue)

    def showResult(resu ltvalue):
    //display on canvas


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

    def callback(value) :
    self.userentere dvalue=value
    def callGUI(self,re sultvalue):
    self.myapp.show Result(resultva lue)

    if __name__ == "__main__":
    controller=MyCo ntroller()
    controller.crea teGUI()
    resultTodisplay =self.userenter edvalue+1000 # or may be call some
    program to do the calc
    controller.call GUI(resultTodis play)

    Here,root.mainl oop() 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
Working...