You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Idle: require tk 8.5 and ttk widgets, and drop unneeded code. #68947
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/terryjreedy'closed_at=<Date2016-06-10.22:41:41.175>created_at=<Date2015-07-30.22:18:35.616>labels= ['expert-IDLE', 'type-feature']
title='Idle: require tk 8.5 and ttk widgets, and drop unneeded code.'updated_at=<Date2019-03-23.04:15:36.380>user='https://github.com/terryjreedy'
try:
from tkinter import *
except ImportError:
print("** IDLE can't import Tkinter.\n"
"Your Python may not be configured for Tk. **", file=sys.__stderr__)
sys.exit(1)
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?
try:
from tkinter import ttk
except:
root = Tk()
root.withdraw()
tkMessageBox.showerror("Fatal Idle Import Error",
"Idle cannot import required module tkinter.ttk.\n"
"Click OK to exit.",
parent=root)
sys.exit(1)
I tested by renaming installed 3.5 ttk, editing 3.5 PyShell with 3.4, and clicking 3.5 icon.
roseman commented on Jul 30, 2015
rosemanmannequin
Mannequin
More actions
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"
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 bpo-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 bpo-24745, before continuing.
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 bpo-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.
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.
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
iftk.TkVersion<8.5:
raiseunittest.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 (bpo-27162) would also need an explicit check. (Note added there.)
Activity
terryjreedy commentedon Jul 30, 2015
PyShell currently has this code
try:
from tkinter import *
except ImportError:
print("** IDLE can't import Tkinter.\n"
"Your Python may not be configured for Tk. **", file=sys.__stderr__)
sys.exit(1)
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?
try:
from tkinter import ttk
except:
root = Tk()
root.withdraw()
tkMessageBox.showerror("Fatal Idle Import Error",
"Idle cannot import required module tkinter.ttk.\n"
"Click OK to exit.",
parent=root)
sys.exit(1)
terryjreedy commentedon Jul 30, 2015
I tested by renaming installed 3.5 ttk, editing 3.5 PyShell with 3.4, and clicking 3.5 icon.
roseman commentedon Jul 30, 2015
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"
python-dev commentedon Jul 31, 2015
New changeset 8203fc75b3d2 by Terry Jan Reedy in branch '2.7':
bpo-24759: Gracefull exit Idle if ttk import fails.
https://hg.python.org/cpython/rev/8203fc75b3d2
New changeset 13a8782a775e by Terry Jan Reedy in branch '3.4':
bpo-24759: Gracefull exit Idle if ttk import fails.
https://hg.python.org/cpython/rev/13a8782a775e
terryjreedy commentedon Jul 31, 2015
Improved message. Thanks. Should be good enough for the extremely few times it should ever be triggered.
serhiy-storchaka commentedon Aug 1, 2015
IMHO Tcl and Tk should be in title case (as Python or Django) or at least all in upper case (as APL or SDL).
serhiy-storchaka commentedon Aug 1, 2015
I don't see any mentions of ttk in IDLE source code except added check. Is ttk really required for IDLE?
terryjreedy commentedon Aug 1, 2015
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 bpo-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 bpo-24745, before continuing.
terryjreedy commentedon Aug 2, 2015
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 bpo-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.
[-]Idle: require 8.5 / ttk[/-][+]Idle: require ttk (and tcl/tk 8.5)[/+]roseman commentedon Aug 2, 2015
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...?
11 remaining items
terryjreedy commentedon Jun 3, 2016
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.
serhiy-storchaka commentedon Jun 3, 2016
Do you forgot to attach a patch?
terryjreedy commentedon Jun 3, 2016
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.
serhiy-storchaka commentedon Jun 3, 2016
Did you try to run tests with Tk 8.4?
terryjreedy commentedon Jun 3, 2016
No, 3.4 is security fixes only and this is a 3.6 only issue.
serhiy-storchaka commentedon Jun 3, 2016
I meant Tk 8.4, not Python 3.4.
Tests should be either passed or skipped, no errors raised.
terryjreedy commentedon Jun 3, 2016
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
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 (bpo-27162) would also need an explicit check. (Note added there.)
python-dev commentedon Jun 4, 2016
New changeset e6560f018845 by Terry Jan Reedy in branch '2.7':
Issue bpo-24759: Add 'private' notice for idlelib.idle_test.
https://hg.python.org/cpython/rev/e6560f018845
New changeset d75a25b3abe1 by Terry Jan Reedy in branch '3.5':
Issue bpo-24759: Add 'private' notice for idlelib.idle_test.
https://hg.python.org/cpython/rev/d75a25b3abe1
terryjreedy commentedon Jun 4, 2016
I believe require85-v2.diff adds everything specified in my last post.
terryjreedy commentedon Jun 6, 2016
Fixed whitespace and added comment.
python-dev commentedon Jun 10, 2016
New changeset 81927f86fa3a by Terry Jan Reedy in branch 'default':
Issue bpo-24759: Add test for IDLE syntax colorizoer.
https://hg.python.org/cpython/rev/81927f86fa3a
python-dev commentedon Jun 10, 2016
New changeset 76f831e4b806 by Terry Jan Reedy in branch 'default':
Issue bpo-24759: IDLE requires tk 8.5 and availability ttk widgets.
https://hg.python.org/cpython/rev/76f831e4b806