newbie doubt about MVC,tkinter

G

gordon

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,138
Latest member
NevilleLam
Top