[Tkinter-discuss] separation gui from logic
Russell E. Owen
rowen at cesmail.net
Mon Nov 21 22:06:30 CET 2005
In article <436D9629.7090902 at post.cz>, Pavel Kosina <geon at post.cz>
wrote:
> In Tkinter I try put to gui design into one file, and in another file
> do: import gui design file and the script logic itself.
> I am not much successful, especially at callback functions, that are
> included in gui design files, f.e. Button(text='Tisk', command=hello),
> and refer to functions that exist in the main script.
>
> Is it somehow possible to do this? Not just this example of Button (how
> to solve reffering to function that not exists yet, and exists in
> "upper" program only), but this whole idea of separation....
Consider coding the logic as methods of an object. Create an instance of
this and pass it to your GUI class at instantiation. Your GUI class then
references the relevant methods for its callbacks.
I use this technique for separating data and the GUI (e.g.
model-view-controller pattern). The model consists of one or more
objects that contain the data. The GUI can then query and update the
model as appropriate. I usually mix the logic (controller) in with the
GUI and model, but it can also be a separate object.
-- Russell
More information about the Tkinter-discuss
mailing list