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.

Title: Idle: require tk 8.5 and ttk widgets, and drop unneeded code.
Type: enhancement Stage: resolved
Components: IDLE Versions: Python 3.6
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: Al.Sweigart, markroseman, ncoghlan, ned.deily, python-dev, serhiy.storchaka, terry.reedy
Priority: normal Keywords: patch

Created on 2015-07-30 22:18 by terry.reedy, last changed 2022-04-11 14:58 by admin. This issue is now closed.

File name Uploaded Description Edit
require85.diff terry.reedy, 2016-06-03 15:44 review
require85-v2.diff terry.reedy, 2016-06-04 20:31 review
require85-v3.diff terry.reedy, 2016-06-06 02:13 review
Messages (31)
msg247701 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-07-30 22:18
PyShell currently has this code

    from tkinter import *
except ImportError:
    print("** IDLE can't import Tkinter.\n"
          "Your Python may not be configured for Tk. **", file=sys.__stderr__)
import tkinter.messagebox as tkMessageBox

When Idle is started from an icon, there is no place for the error message to go, so it appears than nothing happens.  But this is the best we can do without invoking system specific error message functions.  (This, if possible, would be another issue.) The second import assumes that messagebox is available, which is should be without modification of the tkinter package since long ago.  But I think we should guard against someone trying to start Idle on pre 8.5.  The following seems to work nicely.  This is a prerequisite for any ttk patches.  Any comment before I apply?

    from tkinter import ttk
    root = Tk()
    tkMessageBox.showerror("Fatal Idle Import Error",
            "Idle cannot import required module tkinter.ttk.\n"
            "Click OK to exit.",
msg247702 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-07-30 22:21
I tested by renaming installed 3.5 ttk, editing 3.5 PyShell with 3.4, and clicking 3.5 icon.
msg247703 - (view) Author: Mark Roseman (markroseman) * Date: 2015-07-30 22:30
Sounds good. Only suggestion, given it's user facing, is to have the error message point them towards a solution. Off the top of my head, maybe something like "IDLE requires Python be configured to use Tk 8.5 or newer (you have Tk x.x)" with a title of "IDLE Cannot be Started"
msg247721 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-07-31 01:17
New changeset 8203fc75b3d2 by Terry Jan Reedy in branch '2.7':
Issue 24759: Gracefull exit Idle if ttk import fails.

New changeset 13a8782a775e by Terry Jan Reedy in branch '3.4':
Issue 24759: Gracefull exit Idle if ttk import fails.
msg247722 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-07-31 01:19
Improved message.  Thanks.  Should be good enough for the extremely few times it should ever be triggered.
msg247810 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-08-01 14:23
IMHO Tcl and Tk should be in title case (as Python or Django) or at least all in upper case (as APL or SDL).
msg247811 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-08-01 14:26
I don't see any mentions of ttk in IDLE source code except added check. Is ttk really required for IDLE?
msg247816 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-08-01 18:17
Re-opened for tweak.

This patch, to exit gracefully if ttk is not available, is the first step before using ttk in Idle.  Mark, a long-time tk/ttk expert and site/book author, has volunteered to help upgrade Idle with ttk. Please see "ttk in idle" on Idle-Sig list for general discussion and #24750 for the first substantive patches. The only reason I have not applied the ttk.Scrollbar patch, on that issue, is because Ned mentioned, on that issue, that the OS 8.5 python requires tcl/tk 8.4.  I strongly feel that this should not stop the use of ttk, but I an first doing a few non-ttk patches, including Mark's patch for #24745, before continuing.
msg247843 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-08-02 00:51
Re-reading PEP 434, I was mistaken to apply this patch to 2.7 and 3.4 without further discussion.  The PEP says "The PEP would apply to minor ..., but not necessarily to possible major re-writes such as switching to themed widgets ... ." 

Nick, should I post something on python-ideas or pydev, or continue here (moved from #24750) about making the switch also in 2.7 and 3.4?

I believe it would be best overall to at upgrade Idle 2.7, but I will not cry if we stop patching it now. Ditto for 3.4, which will soon get security fixes only anyway.  I am ok with using ttk starting with 3.5.
msg247845 - (view) Author: Mark Roseman (markroseman) * Date: 2015-08-02 01:11
Got it re: 2.7/3.4. So the only stumbling block left to 8.5/ttk in 3.5 would be the current Mac build that is ok with Tcl/Tk 8.4...?
msg247854 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-08-02 04:37
Ttk widgets are partially compatible with Tk widgets, so in many cases it is possible to make partial upgrade without major rewriting. Some changes perhaps need major rewriting (using styles, changing layout), and I think this is what the PEP does not allow. However it is possible that all changes can be done without major rewriting, we don't know until try.
msg247860 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-08-02 09:46
If 2.7 and 3.4 are left out of consideration, then, AFAIK, the only people necessarily affected are those with a PowerPC with OS 10.5 who upgrade to python3.5 and also want to run Idle. People with an Intel machine instead might be if there is no python3.5 that will run with the ActiveState 8.5 that Mark says works on Intel 10.5 machines.  I wish I know how many people that is.  I suspect a tiny fraction of Idle users and of people with such machines.  But ...

The compatibility approach will work for Scrollbars, but I am dubious about other widgets.  For instance, tk Buttons have at least 31 options.  ttk Buttons have 9 of the same + style (and class_, which I do not thing we would use), leaving 22 tk-only options. 

To write tk&ttk code *in one file*, I believe
  ...ttk.Button(parent, <options>, style='xyz')
would have to be written (compactly) as something like
  b=...Button(parent, <common options>)
  b.config(**({'style':'xyz'} if ttk else { <tk style options>}))
or (expansively, in 5 lines)
  b=...Button(parent, <common options>)
  if ttk:
    b['style'] = 'xyz'
    b.config(<tk style options in '=' format>})

I consider this impractical.  I am unwilling to write code that way, in part because it would have to be carefully tested both with and without ttk -- by hand.  I cannot imagine anyone else doing so either. It also does not work for uses of ttk.Treeview, whose API is different from the multiple classes used in Path and Class (Module) browser).  I believe the same is true for ttk.Notebook and the idlelib tab widget.

What I already planned to do instead is copy existing dialog code to new files, possibly refactored, with pep8 filenames and internal names style.  I already planned to leave the existing files in place for now, though as zombies, in case of any external code imports.  With a little more work, it should be possible to optionally use either old or new files. Most of the work would be done with alternate bindings to menu items and accelerator keys, such as Find in Files and Alt-F3.

It might be more acceptible to use ttk in 2.7 and 3.4 as an option rather than as a replacement.  Though I would only commit a ttk version when confident that is works, leaving the option to switch back would add a safety factor.  I changed the title and will revert the patch later.
msg247862 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-08-02 10:27
Note also that committed patch doesn't work at all. "from tkinter import ttk" doesn't raise an exception with Tcl/Tk 8.4. See my patch in issue24750 that does working check.

I consider impractical complex code for supporting 8.4 and ttk too. But in simplest cases this can be done easy.
msg247896 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-08-02 21:00
I realize now that tkinter.ttk is (normally) present and will define Python classes even if the tk widgets needed for them to work are not present.  More comments on the added module on #24750
msg247963 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-08-03 22:45
New changeset 0511b1165bb6 by Terry Jan Reedy in branch '2.7':
Issue #24759: Revert 8203fc75b3d2.

New changeset 06852194f541 by Terry Jan Reedy in branch '3.4':
Issue #24759: Revert 13a8782a775e.

New changeset 863e3cdbbabe by Terry Jan Reedy in branch '3.5':
Issue #24759: Merge with 3.4

New changeset 3bcb184b62f8 by Terry Jan Reedy in branch 'default':
Issue #24759: Merge with 3.5
msg247993 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-08-04 19:43
A second specific reason to make ttk optional is either they or the accompanying re-writing may (and probably will) break some extension that goes beyond the narrowly defined extension interface.  For the present, a user using such an extension would be able to continue to do so, by turning use_ttk off. (I plan to add some DeprecationWarnings, either at startup or old tk module import, when use_ttk is possible but turned off.)

The normal bugfix-only policy, and the Idle exemption, starts with each x.y.0b1 release. The point of excluding 'major re-writes such as switching to themed widgets' was to exclude changes in bugfix releases that prevent idle from running in the 'current' environment.  In private email, Nick agreed with me that with ttk and any possible disablement made optional, it can be added to all current releases. He also suggested being on by default when possible.

I decided not to put anything into 3.5.0.  I intend to start pushing ttk patches perhaps next week after the release branch is split off and the main 3.5 branch is 3.5.1.
msg248031 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2015-08-05 12:28
IDLE's in an "interesting" place right now - it isn't showing people Tcl/Tk in its best light, so folks are likely to assume all Tcl/Tk apps necessarily look that way, and it's also using GUI idioms like separate shell and editor windows that don't reflect the conventions of modern IDEs.

For 3.5.1+, I think there's no question that we want to show IDLE in the best possible light, and we want to try to do that by default. That means modernising it to use the best cross-platform features that Tcl/Tk has to offer (including ttk).

However, Ned pointed out that the last PPC-supporting Mac OS X (10.5) has a Tcl/Tk version older than 8.5, and there's the general compatibility risk for breaking extensions with large refactorings, so retaining a "non-ttk mode" will be a valuable approach to the modernisation effort.
msg266743 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-05-31 07:31
In msg265349, Ned stated that running IDLE with 8.4 should no longer be a requirement in 3.6.  Hence the revised title and restriction to 3.6.

Serhiy, I read the code in your #24750 patch.  Should it not be enough to first check tkinter.Tkversion >= 8.5 before trying to import ttk. And is testing ttk then needed?  Is it possible for ttk to not work in 8.5/6)?

Tkversion (or a refinement thereof) is already checked in colorizer, config, editor, macosx, and pyshell.  With one check on startup, existing check can be eliminated, along with code only for older versions.
msg266803 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-06-01 07:36
My patch in issue24750 makes sense only if we want support Tcl/Tk 8.4. I think that if require Tcl/Tk 8.5+, we can use Ttk directly and unconditionally. I don't think that it can be not working.
msg267077 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-06-03 07:59
Given what Serhiy said, the core of this patch is the original patch with a test of TkVersion instead of importing ttk.  Code that only ran for 8.4- is removed.  Some minimal new tests are added, and I may add some more.  None of the changes should depend on OS.  I want to apply this in a few days as it is a prerequisite for ttk patches.
msg267080 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-06-03 08:12
Do you forgot to attach a patch?
msg267108 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-06-03 15:44
Trying again.  And yes, I would like a review.  I don't think there is anything system specific, but some deletions required a minor rewrite.
msg267145 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-06-03 19:23
Did you try to run tests with Tk 8.4?
msg267154 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-06-03 20:00
No, 3.4 is security fixes only and this is a 3.6 only issue.
msg267156 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-06-03 20:15
I meant Tk 8.4, not Python 3.4.

Tests should be either passed or skipped, no errors raised.
msg267180 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-06-03 22:33
I saw the review comment about adding lines.

I do not have 8.4 either, but I get the point: the startup version check does not not guard the unittests.  After test.text_idle imports unittest and tkinter (as tk) (line 6), I will add

if tk.TkVersion < 8.5:
    raise unittest.SkipTest("IDLE requires tk 8.5 or later.")

I will add a 'private API' and version-required notice to idlelib.idle_test.__init__.  I will add version required to the notice already in idlelib.__init__.

For similar reasons, the proposed interface module (#27162) would also need an explicit check.  (Note added there.)
msg267311 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-06-04 20:16
New changeset e6560f018845 by Terry Jan Reedy in branch '2.7':
Issue #24759: Add 'private' notice for idlelib.idle_test.

New changeset d75a25b3abe1 by Terry Jan Reedy in branch '3.5':
Issue #24759: Add 'private' notice for idlelib.idle_test.
msg267313 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-06-04 20:31
I believe require85-v2.diff adds everything specified in my last post.
msg267502 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-06-06 02:13
Fixed whitespace and added comment.
msg268073 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-06-10 01:04
New changeset 81927f86fa3a by Terry Jan Reedy in branch 'default':
Issue #24759: Add test for IDLE syntax colorizoer.
msg268074 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-06-10 01:09
New changeset 76f831e4b806 by Terry Jan Reedy in branch 'default':
Issue #24759: IDLE requires tk 8.5 and availability ttk widgets.
Date User Action Args
2022-04-11 14:58:19adminsetgithub: 68947
2019-03-23 04:15:36terry.reedysetcomponents: + IDLE
2016-06-10 22:41:41terry.reedysetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2016-06-10 01:09:33python-devsetmessages: + msg268074
2016-06-10 01:04:26python-devsetmessages: + msg268073
2016-06-06 02:13:14terry.reedysetfiles: + require85-v3.diff

messages: + msg267502
2016-06-04 20:31:04terry.reedysetfiles: + require85-v2.diff

messages: + msg267313
2016-06-04 20:16:32python-devsetmessages: + msg267311
2016-06-03 22:33:16terry.reedysetmessages: + msg267180
2016-06-03 20:15:08serhiy.storchakasetmessages: + msg267156
2016-06-03 20:00:04terry.reedysetmessages: + msg267154
2016-06-03 19:23:53serhiy.storchakasetmessages: + msg267145
2016-06-03 15:44:19terry.reedysetfiles: + require85.diff
keywords: + patch
messages: + msg267108
2016-06-03 08:12:20serhiy.storchakasetmessages: + msg267080
2016-06-03 07:59:36terry.reedysetmessages: + msg267077
stage: needs patch -> patch review
2016-06-01 07:36:23serhiy.storchakasetmessages: + msg266803
2016-05-31 07:31:36terry.reedysettitle: Idle: add ttk widgets as an option -> Idle: require tk 8.5 and ttk widgets, and drop unneeded code.
messages: + msg266743
versions: - Python 2.7, Python 3.4, Python 3.5
2016-05-31 07:03:53terry.reedylinkissue27163 dependencies
2015-08-05 17:21:44Al.Sweigartsetnosy: + Al.Sweigart
2015-08-05 12:29:03ncoghlansetnosy: + ned.deily
messages: + msg248031
2015-08-04 19:43:36terry.reedysetmessages: + msg247993
2015-08-03 22:45:36python-devsetmessages: + msg247963
2015-08-02 21:00:57terry.reedysetmessages: + msg247896
2015-08-02 10:27:10serhiy.storchakasetmessages: + msg247862
2015-08-02 09:46:03terry.reedysettitle: Idle: require ttk (and tcl/tk 8.5) -> Idle: add ttk widgets as an option
messages: + msg247860
stage: needs patch
2015-08-02 04:37:48serhiy.storchakasetmessages: + msg247854
2015-08-02 01:11:21markrosemansetmessages: + msg247845
2015-08-02 00:51:33terry.reedysetnosy: + ncoghlan
title: Idle: require 8.5 / ttk -> Idle: require ttk (and tcl/tk 8.5)
messages: + msg247843

resolution: fixed -> (no value)
stage: resolved -> (no value)
2015-08-01 18:17:59terry.reedysetstatus: closed -> open

messages: + msg247816
2015-08-01 14:26:31serhiy.storchakasetmessages: + msg247811
2015-08-01 14:23:08serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg247810
2015-07-31 01:19:40terry.reedysetstatus: open -> closed
resolution: fixed
messages: + msg247722

stage: commit review -> resolved
2015-07-31 01:17:53python-devsetnosy: + python-dev
messages: + msg247721
2015-07-30 22:51:52terry.reedylinkissue24750 dependencies
2015-07-30 22:30:24markrosemansetmessages: + msg247703
2015-07-30 22:21:49terry.reedysetmessages: + msg247702
stage: needs patch -> commit review
2015-07-30 22:18:35terry.reedycreate