tkinter how to write

faulkner faulkner891 at gmail.com
Thu Mar 8 03:54:40 CET 2007


On Mar 8, 7:07 pm, Gigs_ <g... at hi.t-com.hr> wrote:
> as I write my first gui program (text editor) I wanna ask you guys how
> to separate code in classes.?
> Should I put in one class my menu and in another class text and
> scorllbars etc?
>
> or something else?
>
> thanks


Use the force. Do whatever feels most right. Remember that you can
always refactor.
A good rule of thumb for GUIs is MVC [a class or set of classes to
encapsulate the abstract relationships known as the Model, another
class or set of classes to handle translating changes to the model
into changes in the GUI aka View, and another class or set of classes
to encapsulate the Controlling of everything], but do not pursue this
to its extreme inanity as Java does. Follow guidelines only so long as
they clarify the code. The second you can no longer keep the overall
structure of the code in your head at once, hit control+z until you
can.

When I wrote my text editor, I wanted to keep everything in one class
because I thought it would be cleaner. Several thousand lines later, I
realized that the notion of a Tab is a significant and powerful
abstraction, as is the UndoStack and the entries in it [UndoEntry].
Right now, I'm thinking about separating all the menuitem callbacks
into their own class because they are different in kind from the
methods which encapsulate the Tabs, menubar, statusbar, etc. into an
application. The reason that I probably won't do this is that a class
is not for grouping methods, it's for representing objects.

UML is another expounded tool for achieving OOP zen before you set
fingertips to keyboard. i've never grokked it, but you should try it
at least once, if only so you can say that you have in a job interview.




More information about the Python-list mailing list