how to separate view and controller in python tkinter? -


i have problem tkinter regarding separating ui , ui functionality in 2 modules,here code:

1-view.py

from tkinter import *  class view():     def __init__(self,parent):         self.button=button(parent,text='click me').pack() 

2.controller.py

from tkinter import * view import *  class controller:     def __init__(self,parent):         self.view1=view(parent)         self.view1.button.config(command=self.callback)      def callback(self):         print('hello world!')   root=tk() app=controller(root) root.mainloop() 

on running controller.py following error:

attributeerror: 'nonetype' object has no attribute 'config'

any suggestion?

also tried use lambda using callback function in module didn't work.

thanks in advance

in view.py calling:

self.button=button(parent,text='click me').pack()

the pack function doesn't return button object want assign self.button, causes attributeerror later on. should do:

self.button = button(parent, text='click me') self.button.pack() 

Comments