I have a problem with tkinter regarding separating UI and UI functionality in two modules,here is my 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 *
from 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 I get the following error:
AttributeError: 'NoneType' object has no attribute 'config'
any suggestion?
also I tried to use lambda for using a callback function in another module but it didn't work.
thanks in advance