[Tkinter-discuss] Zen of Learning Tkinter or any other type of technology out there for that matter

Harlin Seritt harlinseritt at yahoo.com
Fri Jun 17 21:09:58 CEST 2005


Hi William,
 
True, you can get some rather curt answers on some of these lists -- try not to take these sort of things too personally but rather take what you need from it and discard the rest. If you fight back, no doubt you'll get a flame going or --most likely-- you'll get ignored and almost certainly no one will help you again. So, in short, you can't control what others do -- in life or online.
 
Now onto Tkinter... My advice to you as far as really getting into Tkinter and understanding how it all works is for you to take a look at Frederik Lundh's fine tutorial and reference here: http://www.pythonware.com/library/tkinter/introduction/. This was more than adequate to get me up and running about 2 years ago. Once you get an idea of the basic framework of how Tkinter works, you may begin to think like I do: How come other GUI toolkits (simple ones like Java Swing, .NET et al) are not organized and thought out in the same fashion?
 
I'll give you an example of what I mean. Tkinter GUI construction is based on a few components that you'll see over and over:
 
Widget classes themselves: Ex: Button, Label, Entry
Widget options: Ex: bordersize, relief, text, etc.
Widget methods: Ex: config(), after(), etc.
 
Also there are other components to consider:
 
Placing widgets: You'll find these three methods are all you'll need for layout...
 
pack(): the most difficult perhaps but gives you the most flexibility ... certainly easier than using most of Java Swing layouts ;-)
grid(): allows one to place widgets in a grid
place(): if you insist on having total control of placement then use this. Note that it won't look near as good as pack() if your user tries to expand your app.
 
Custom events (bind()): Most of the Tkinter widgets will have their own default events but by designing your own you'll find that you can have an almost infinite arrangement of events.
 
Window protocols: These allow you to manipulate the windows almost like MFC or X/Motif (well, at least to me!)
 
Tkinter constants: As 'constant' implies, there are many pre-designed constants that allow one to use very plain language to describe a widget's option or set variables that correspond to widget values.
 
And there are quite a few others, but I'll let you discover them on your own ;-). You'll find that you don't have to have a lot of underlying GUI framework knowledge (for your particular platform) to pull off a great-looking GUI app in just a few minutes!
 
After you're done with Mr. Lundh's fine tutorial, I suggest you go buy John Grayson's Python_and_Tkinter_Programming book from Manning publications (you can get it here: http://www.manning.com/books/grayson). It is almost 700 pages of pure Tkinter code. If I'm not mistaken, these days you can actually buy it in PDF format! Some of it is intermediate and advanced, so I advise you to look hard at the aforementioned tutorial and post your questions as well on comp.lang.python newsgroup before really diving in. You'll find that you'll get help from a lot of different Tkinter pros there -- even from the effbot himself (Frederik).
 
An extra note... in the John Grayson book in the preface, John mentions that he is an avid martial arts disciple. In it one of his teachers mentions to him and other students that there are a few concepts that might not be taught directly. The master tells them a lot of times you'll have to STEAL these concepts from me. And so, you must do that occasionally. Google is your friend, as the saying goes. Google as much as possible. Read books. Ask many many questions in the right places while ignoring flames when appropriate but always learn from what tidbits you'll be given from these people. Technologists are only too happy to show how much they know even if they intend to mildly insult you. Steal their knowledge whenever possible.
 
Sorry for all the zen but hopefully this helps you.
 
Good luck,
 
Harlin Seritt
 


tkinter-discuss-request at python.org wrote:
Send Tkinter-discuss mailing list submissions to
tkinter-discuss at python.org

To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/tkinter-discuss
or, via email, send a message with subject or body 'help' to
tkinter-discuss-request at python.org

You can reach the person managing the list at
tkinter-discuss-owner at python.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tkinter-discuss digest..."


Today's Topics:

1. Re: First Tkinter program (William O'Higgins)
2. Re: First Tkinter program (Jeff Epler)


----------------------------------------------------------------------

Message: 1
Date: Thu, 16 Jun 2005 09:45:29 -0400
From: William O'Higgins 
Subject: Re: [Tkinter-discuss] First Tkinter program
To: tk 
Message-ID: <20050616134529.GA7948 at sillyrabbi.dyndns.org>
Content-Type: text/plain; charset="us-ascii"

On Wed, Jun 15, 2005 at 01:35:38PM -0600, Stewart Midwinter wrote:
>William, you sound like a candidate for one of the many introductions
>to Tkinter that are available. You found this list, so that's a
>start. Now you could try visiting the Tkinter wiki and take a look
>at some of the resources available there. It's at
>http://tkinter.unpy.net/wiki/

I have been to the wiki, but like all wikis, it is incomplete, the
widgets I need more explanation of are not covered (listbox for example)
and the recipes are overspecialized. The links to other resources are
the same as those on python.org, which I have exhausted before
contacting this list.

>Unless what you are asking is for someone to write some widgets for
>you,

No, what I need is some explanatory help on what the structures inherent
in Tkinter code *mean*.

>there is no alternative to investing some time to learn the
>basics of Tkinter. Otherwise you will flail around endlessly and in
>the end spend more time than if you had devoted a minimal amount of
>time to educating yourself.

Thank you for flip assessment of the time I've spent, but you have no
idea what I've done before contacting the list (which is partly my fault
for not explaining my work to date). I would think that on a list with
as little volume as this one you might be more polite.

Now, perhaps someone else could contribute - here's what I need:

Is there a reason that all the example programs I've seen start by
defining a class for the actions, which has an __init__ function that
refers to "self" all over the place, then creates an instance of a Tk()
object, and then calls the class for the actions on (with?) the new
Tk()instance?

None of the examples seem to code in a straight line, and I'm having 
trouble following the progression of the "simple" examples. Can Tkinter
programs been developed in a flat structure, without the class within
class stuff that's hindering my understanding? Thanks.
-- 

yours,

William

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050616/8411258c/attachment-0001.pgp

------------------------------

Message: 2
Date: Thu, 16 Jun 2005 12:12:08 -0500
From: Jeff Epler 
Subject: Re: [Tkinter-discuss] First Tkinter program
To: "William O'Higgins" 
Cc: tk 
Message-ID: <20050616171208.GB1763 at unpythonic.net>
Content-Type: text/plain; charset="us-ascii"

On Thu, Jun 16, 2005 at 09:45:29AM -0400, William O'Higgins wrote:
> None of the examples seem to code in a straight line, and I'm having 
> trouble following the progression of the "simple" examples. Can Tkinter
> programs been developed in a flat structure, without the class within
> class stuff that's hindering my understanding? Thanks.

Sure they can. I didn't read your original post, but here's a
straight-line Tkinter program that creates a listbox with a scrollbar. When the
selected item changes, the 'changed' function is executed, and prints (to the
console) some information about the selection. Of course, this example *does*
use classes, since Tkinter.Tk, Tkinter.Scrollbar, and friends are all classes.

Jeff

from Tkinter import *

t = Tk()
s = Scrollbar(t)
l = Listbox(t, yscrollcommand=s.set)
s.configure(command=l.yview)

l.pack(side=LEFT, fill=BOTH, expand=YES)
s.pack(side=LEFT, fill=Y)

for i in range(1, 101):
l.insert(END, "Item %d" % i)

def changed(event):
index = event.widget.curselection()
if isinstance(index, (list, tuple)): index = index[0]
print "Item index:", index
print "Item value:", event.widget.get(index)
l.bind("<
>", changed)

t.mainloop()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050616/f0239f92/attachment-0001.pgp

------------------------------

_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss at python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss


End of Tkinter-discuss Digest, Vol 16, Issue 5
**********************************************

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20050617/e483f3fc/attachment.htm


More information about the Tkinter-discuss mailing list