Martin Franklin | 1 Jun 2005 13:42
Picon

Re: tk 8.3 and unicode

Jeff Epler wrote:
> This bug must have been fixed between Python 2.2 + Tk 8.3 and Python 2.3
> + Tk 8.4.
> 
> Running a slightly different test program, I get this output on Fedora
> Core 1 (Python 2.2 + Tk 8.3):
>     '\xc2\xa3'
> and this output on Fedora Core 2 (Python 2.3 + Tk 8.4):
>     u'\xa3'
> 
> You could try defining a
>     class UStringVar(Tkinter.StringVar):
>         def get(self):
>             return Tkinter.StringVar.get(self).decode("utf-8")
> and using that instead.  This seemed to work on the FC1 system, at least
> when LANG=en_US.UTF-8 -- this might depend on tcl's idea of the sytem
> encoding, though.
> 

Thanks Jeff,

The call to decode() when I get the entry's textvariable does indeed fix
the problem.  I now have a similar (but wholly different;-) problem
related to a filename containing a Unicode character, however, I think
I'll resolve this but not allowing my users to do this (I believe it is
dependent on more than just Python / Tk - It must involve the OS at some
level)

Cheers,
Martin.
(Continue reading)

Greg Lee | 7 Jun 2005 04:30

tkinter and threading

Are Tkinter callbacks run in separate threads?  Do I need to use threading locks to protect data shared
between callbacks that can run at the same time? I'm running Python 2.3 and Tkinter on Windows.

I have two callbacks: cb_close and cb_run.  cb_close cleans up, then uses Tkinter.Toplevel.destroy; it is
bound to WM_DELETE_WINDOW via Tkinter.Toplevel.protocol.

cb_run uses a COM component to perform a lengthy operation.  The COM component calls back to the Python world
often enough that I can keep my GUI responsive using Tkinter.Toplevel.update.

Bad things happen if I allow cb_close to call destroy while cb_run is in progress: cb_run eventually asks
the Tkinter world to post a completion dialog.  To keep this from happening I use a state variable to tell
cb_close that it should not call destroy if cb_run is in progress and to tell cb_run that it should not
execute if a cb_close is in progress.

I can definitely get cb_close to run at the same time as cb_run, which suggests that the Tkinter eventloop
executes its callbacks in separate threads.  All this lead me to use a lock to protect read/write of the
state variable.  Was this necessary?  Is there something in the way that Tkinter handles callbacks that
automatically protects shared data structures?

--------------------------------------------
Greg Lee / Pharsight Corporation / Suite 200
800 W El Camino / Mountain View CA 94040
voice: 650-314-3860 / fax: 650-314-3810

This email message (including any attachments) 
is for the sole use of the intended recipient 
and may contain confidential  and proprietary
information.  Any disclosure or distribution 
to third parties that is not specifically 
authorized by the sender is prohibited.  
(Continue reading)

Mark English | 7 Jun 2005 10:58

Re: gui/thread issues

> Date: Mon, 23 May 2005 14:25:04 -0400
> From: Perry Greenfield <perry <at> stsci.edu>
> I think the problem is that, by and large, almost all uses of GUIs
> are centered on their being standalone applications and thus
> little thought is given to having a command line coexisting
> with the GUI.
> Our needs are pretty atypical in this regard.
Count me in as another atypical user. I've had additional problems
running through a plain Python interpreter if I don't use the main
process thread as the main GUI thread on Windows XP. Typically the
program will simply crash at some point. I'd like to be able to just
import a module and call a function to run its GUI and still be able to
continue at the command prompt. I suspect if I understood Tkinter better
I could make this problem go away, which makes it all the more
frustrating. When I have the time I'll try to create a simple test case
and post it.

Regards,
Mark

-----------------------------------------------------------------------
The information contained in this e-mail is confidential and solely 
for the intended addressee(s). Unauthorised reproduction, disclosure, 
modification, and/or distribution of this email may be unlawful. If you 
have received this email in error, please notify the sender immediately 
and delete it from your system. The views expressed in this message 
do not necessarily reflect those of LIFFE Holdings Plc or any of its subsidiary companies.
-----------------------------------------------------------------------
Jeff Epler | 7 Jun 2005 15:57
Favicon

Re: tkinter and threading

No, Tkinter callbacks are not run in separate threads.

When you see cb_close being called during cb_run, it's all in a single
thread, with a call stack that looks like
    cb_close    
    update
    cb_run
    mainloop
i.e., when cb_run calls update, events (including "the user clicked a
button", "pressed a key", etc.) are handled, leading to this effect.

You may be able to use update_idletasks instead of update.  They have
different semantics as to which events they handle.  update_idletasks
should let things like resizing and repainting windows work, while
delaying the response to user actions like clicking until an update or a
return to the mainloop.

I've included a copy of the update manpage below.  Tcl's "update" command is
the .update() method, and "update idletasks" is the .update_idletasks() method.

Jeff

update(n)                    Tcl Built-In Commands                   update(n)

______________________________________________________________________________

NAME
       update - Process pending events and idle callbacks

SYNOPSIS
(Continue reading)

William O'Higgins | 15 Jun 2005 18:23
Picon
Picon
Favicon

First Tkinter program

I am just starting out with Python, in hopes of getting my head around
OO programming.  I am running into trouble figuring out how to structure
a GUI front-end for a simple program.  Here's the general visual
structure:

Listbox populated by a list

Some number of textentry and textarea pairs (five? or from a list?)

Button one - says "Next" and it stores the contents of the textentry and
textarea pairs (in a dictionary tied to the list entry seems natural), and 
then clears the interface to allow more entries

Button two - "Done" - stores the contents of the textentry and textarea
pairs and then closes the window.

That's really it - very simple, but too much for me - I haven't even
written a list box test that actually works - I do not understand OO
well enough to make sense of examples (I don't really get what a
constructor does, or understand the interactions of classes and
instances of TKinter objects).

The underlying functionality is easy - I can write it to use the command
line or text files no problem - but the interface i giving me fits.  Any
pointers would be welcome.  Thanks.
--

-- 

yours,

William
(Continue reading)

Stewart Midwinter | 15 Jun 2005 21:36
Picon

Fwd: First Tkinter program

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/

Unless what you are asking is for someone to write some widgets for
you, 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.

cheers
S

--
Stewart Midwinter
stewart <at> midwinter.ca
stewart.midwinter <at> gmail.com
Skype: midtoad
William O'Higgins | 16 Jun 2005 15:45
Picon
Picon
Favicon

Re: First Tkinter program

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:
(Continue reading)

Jeff Epler | 16 Jun 2005 19:12
Favicon

Re: First Tkinter program

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]
(Continue reading)

Harlin Seritt | 17 Jun 2005 21:09
Picon
Favicon

Zen of Learning Tkinter or any other type of technology out there for that matter

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 as king 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 instanc e 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"
C c: 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 impor t *

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> py thon.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

_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss <at> python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss
Michael Lange | 21 Jun 2005 20:01
Picon

Help: _tkinter.createfilehandler not supported for threaded Tcl

Hello list,

the following error happened on a program I wrote that uses tkinter.createfilehandler()
to catch the output of a shell command on someone else's box (for me it runs fine):

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 1345, in __call__
    return self.func(*args)
  File "/usr/local/bin/pyfloppy", line 293, in start
    self.format()
  File "/usr/local/bin/pyfloppy", line 303, in format
    self.mkfilehandler(self.pp, self.get_msg)
  File "/usr/local/bin/pyfloppy", line 379, in mkfilehandler
    tkinter.createfilehandler(fileobject, READABLE, function)
RuntimeError: _tkinter.createfilehandler not supported for threaded Tcl

When I googled for the traceback one of the results said:

> If your Tcl installation is threaded, you should use 
> tkapp.createfilehandler instead.

however (on my box) I cannot find tkapp anywhere (or should it be _tkinter.tkapp ?).

Any help would be greatly appreciated.

Thanks in advance

Michael

Gmane