[Tutor] gui coding

Alan Gauld alan.gauld at btinternet.com
Mon Dec 13 21:08:47 CET 2010


"Rance Hall" <ranceh at gmail.com> wrote

> When I learned FORTRAN years ago they didn't teach us OOP or what I
> like to call Class based programming.

One of the requirements of OOP is to be able to group data together
and from memory FORTRAN didn't have any such construct being
based primarily on arrays. I beliebve Fortran 95 had some kind of
limited OOP facilities but prior to that it was impossible. And my
experience on Fortran was in the 80's!

> I'm intrigued and want to learn but all the samples seem to be OOP 
> or
> class based.

Try not to think of it as class based. Languages like Java tend to
emphasise the class but really you need to think about the actual
objects as the basis of the program. The class is just a template
from which to generate objects. Focussing on the classes as the
core item will lead to bad habits.

> can not find any tkinter samples that use a procedural approach.

The GUI topic in my tutor does not use OOP till near the end.
It is extremely basic but it does show the basics needed to front
a CLI app with a GUI.

> finding it very difficult to understand what I need to get from
> tkinter because the classes are getting in the way and I'm not 
> seeing
> what I need to see.

Tkinter is, like most GUI toolkits heabvily based on objects itself.
But then, so is Python. Strings, files, lists etc are all objects in 
Python.
If you can use those you can use Tkinter.

> Is there something about class based programming that GUI apps 
> prefer
> to work better in?

GUIs are conceptially made up of objects - buttons, menus, windows,
scroll bars etc. There is a very natural mapping from the visual 
objects
(widgets/controls) that you see on-screen and the code objects of the
toolkit. The whole ethos of OOP is that each object is like an 
independent
mini-program responding to events/messages from other objects.
GUI windows reflect that model - a dialog box acts like a mini app
within the parent app and sends data back to it...

> Does anyone have or know of a good tutorial or explanation of class
> based coding that I could have a run at?

Try my tutor. It has topics on both OOP and GUIs.
And before doing the GUI one also  read the event-driven topic because
GUIs are, without exception, event-driven frameworks. Most folks find
the shift to thinking in terms of events harder than the shift to 
objects.
But thinking in events makes objects more natural, so they are 
connected.

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list