This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: IDLE doesn't work with Tk 8.5 under python 2.5 and older
Type: Stage:
Components: IDLE, Tkinter Versions: Python 2.5
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: gpolo, gregc, kbk, loewis
Priority: normal Keywords: patch

Created on 2008-04-25 23:36 by gregc, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
Python-2.5.2-idlelib.patch gregc, 2008-04-25 23:36 Patch to make Python 2.5 IDLE with with Tk 8.5
Messages (7)
msg65828 - (view) Author: Greg Couch (gregc) Date: 2008-04-25 23:36
IDLE and Tk 8.5 don't well work together for both Python 2.5 and 2.6a
(SVN version).  The reasons are related but different.

In Python 2.5, you can't select any text in the IDLE window and whenever
a calltip is to appear, you get a backtrace ending with "invalid literal
for int() with base 10: '(72,'".  That comes from an interaction between
WidgetRedirector's dispatch function and _tkinter.  The Text widget's
bbox method returns a tuple of ints, the dispatch function isn't
monitoring bbox, so it returns the tuple as is to _tkinter, where
PythonCmd converts the tuple to a Python string, not a Tcl list, so when
Tkinter sees the string, it can't convert to a tuple.

The Python "2.6a2" SVN version of _tkinter fixes that bug but exposes
others (Ikinter.py, tupleobject.c), so I've attached a simple patch for
Python 2.5.  The SVN version of idle appears to work, so this patch
should only be on the 2.5 branch.
msg65829 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-04-25 23:52
I'm skeptical about this patch; it may break other things. So Python 2.5
just doesn't support Tcl 8.5 - you need to stay with Tcl 8.4.
msg65873 - (view) Author: Greg Couch (gregc) Date: 2008-04-27 05:48
I wish I could be as cavalier about Tk 8.5.  The last version of Tk 8.4
just came out and it really shows its age, especially on Mac OS X, and
those are ~25% of our application's downloads.  Since Python 2.6a2 is
"not suitable for production use", that leaves us with patching 2.5. 
Backporting, the _tkinter and Tkinter changes, was not hard, but then we
get "SystemError: Objects/tupleobject.c:89: bad argument to internal
function" errors with both the 2.5 and the 2.6a2 idlelibs.  Looking at
the SVN log, it is not clear which patch to tupleobject.c fixed that
problem (does anyone know?).

So fixing WidgetRedirector.py to not screw up the string representation
of tuples is the easiest solution to get idle to work with Tk 8.5. and
Python 2.5 (you still would want the Tkinter.py changes for other
reasons).  A slightly more robust solution would be to use Tcl quoting:

    r = '{%s}' % '} {'.join(map(str, r))

But that has not been important in practice.
msg65874 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-04-27 07:09
> I wish I could be as cavalier about Tk 8.5.  The last version of Tk 8.4
> just came out and it really shows its age, especially on Mac OS X, and
> those are ~25% of our application's downloads.

Still, why is that a problem to use it for IDLE?

> Since Python 2.6a2 is
> "not suitable for production use", that leaves us with patching 2.5. 

If you need to patch Python 2.5, just go ahead and do it. You don't need
your patch accepted for that. Python 2.5.3 will likely be released
*after* Python 2.6, at which point the "not suitable for production use"
argument will be invalid.

> Backporting, the _tkinter and Tkinter changes, was not hard, but then we
> get "SystemError: Objects/tupleobject.c:89: bad argument to internal
> function" errors with both the 2.5 and the 2.6a2 idlelibs.  Looking at
> the SVN log, it is not clear which patch to tupleobject.c fixed that
> problem (does anyone know?).

I don't think there was any such change to tupleobject.c. If you got
the internal error after changing something, you probably changed it
incorrectly.

> So fixing WidgetRedirector.py to not screw up the string representation
> of tuples is the easiest solution to get idle to work with Tk 8.5. and
> Python 2.5 (you still would want the Tkinter.py changes for other
> reasons).  A slightly more robust solution would be to use Tcl quoting:
> 
>     r = '{%s}' % '} {'.join(map(str, r))
> 
> But that has not been important in practice.

This is what I'm concerned about. I cannot accept a patch whose
correctness was just established through testing. In fact, I don't
understand what the proposed change actually does: what are the
values of the variables at the point, what is the expected result,
what is the actual result, and how does the patch change that?
msg65978 - (view) Author: Greg Couch (gregc) Date: 2008-04-29 19:43
Starting over:

The goal of this patch is to get Tk 8.5 to work with Python 2.5's Idle.
 It currently fails with a ValueError, "invalid literal for int() with
base 10: '(72,'" (the 72 changes depending on what was typed in).

The root cause of bug is due to an interaction between Tk 8.5 returning
more results as Tcl lists, instances of Idle's WidgetRedirector class
that wrap widget Tcl commands with the WidgetRedirector's dispatch
method, and _tkinter's internal PythonCmd function that stringifies
anything its gets from Python.  What happens is that when a Python
method is called on a redirected widget, the corresponding Tcl method is
called using the WidgetRedirector's imposter widget command, which calls
the WidgetRedirector's dispatch method from Tcl, which then invokes the
original widget Tcl command, and if that command returns a Tcl list,
_tkinter converts it to a Python tuple, the dispatch method returns the
tuple into _tkinter, _tkinter stringifies it so it looks like a Python
tuple representation instead of a Tcl list representation, returns it to
Tkinter which tries to parse it like a Tcl list representation, and
causes the ValueError.

The correct fix is already in Python 2.6a2, which is changing Text
class' index method in Tkinter.py to return a string, and changing
_tkinter's PythonCmd to convert Python objects to equivalent Tcl
objects.  Unfortunately backporting those simple changes to Python 2.5
cause a "SystemError: Objects/tupleobject.c:89: bad argument to internal
function".  While that is worth further investigation, Python 2.6a2
doesn't have that problem and a simple alternative fix is available for
Python 2.5, so that is for someone else to do.

The alternative fix that works in Python 2.5 is to make sure that the
Tcl list string representation is used for Python tuples that are
returned to _tkinter's PythonCmd.  Those changes are confined to the
WidgetRedirector's dispatch method.  Line 126 of WidgetRedirector.py:

    return self.tk.call((self.orig, operation) + args)

is replaced with:

    result = self.tk.call((self.orig, operation) + args)
    if isinstance(result, tuple):
        # convert to string ourselves so we get a Tcl list
        # that can be converted back into a tuple by Tkinter
        result = '{%s}' % '} {'.join(map(str, result))
    return result

For Tk 8.4, the if clause is never invoked because Idle does not use any
of the Tk 8.4 methods that return Tcl lists (luckily).  In Tk 8.5, the
additional quoting is only needed for the Tk text widget's tag names and
tag ranges commands when spaces are used for tag names (explicitly not
recommended), all other uses are lists of numbers.  Since none of Idle's
Text tags have spaces in them, that line can safely be replaced with:

        result = ' '.join(map(str, result))
msg71254 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2008-08-17 00:50
Hi there,

The revisions you are after are r59653 and r59654.
I really don't see a reason to not patch release25-maint with those ones.
msg78638 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2008-12-31 17:39
Closing as only r59654 was backported to release25-maint, so Tk 8.5 is
not fully supported by the standard Tkinter present in python 2.5.x
History
Date User Action Args
2022-04-11 14:56:33adminsetgithub: 46945
2008-12-31 17:39:46gpolosettitle: IDLE doesn't work with Tk 8.5 -> IDLE doesn't work with Tk 8.5 under python 2.5 and older
2008-12-31 17:39:31gpolosetstatus: open -> closed
resolution: wont fix
messages: + msg78638
2008-08-17 00:50:50gpolosetnosy: + gpolo
messages: + msg71254
2008-04-29 19:44:13gregcsetmessages: + msg65978
2008-04-27 14:06:07kbksetnosy: + kbk
2008-04-27 07:09:55loewissetmessages: + msg65874
2008-04-27 05:48:18gregcsetmessages: + msg65873
2008-04-25 23:52:28loewissetnosy: + loewis
messages: + msg65829
2008-04-25 23:36:27gregccreate