python / cpython

The Python programming language
https://www.python.org
Other
61.81k stars 29.71k forks source link

Key presses are doubled in Tkinter dialog invoked from window close handler with Cocoa Tk #67317

Open b90121a8-fbda-4f47-80a0-100dacdabbfb opened 9 years ago

b90121a8-fbda-4f47-80a0-100dacdabbfb commented 9 years ago
BPO 23128
Nosy @ned-deily

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: ```python assignee = None closed_at = None created_at = labels = ['type-bug', 'expert-tkinter'] title = 'Key presses are doubled in Tkinter dialog invoked from window close handler with Cocoa Tk' updated_at = user = 'https://bugs.python.org/pew' ``` bugs.python.org fields: ```python activity = actor = 'ned.deily' assignee = 'none' closed = False closed_date = None closer = None components = ['Tkinter'] creation = creator = 'pew' dependencies = [] files = [] hgrepos = [] issue_num = 23128 keywords = [] message_count = 4.0 messages = ['233177', '233186', '233207', '235487'] nosy_count = 2.0 nosy_names = ['ned.deily', 'pew'] pr_nums = [] priority = 'normal' resolution = None stage = 'needs patch' status = 'open' superseder = None type = 'behavior' url = 'https://bugs.python.org/issue23128' versions = ['Python 2.7', 'Python 3.4', 'Python 3.5'] ```

b90121a8-fbda-4f47-80a0-100dacdabbfb commented 9 years ago

Minimal code example:

from Tkinter import Tk
from tkSimpleDialog import askstring

def close_handler():
    askstring('', '')
    root.destroy()

root = Tk()
root.protocol('WM_DELETE_WINDOW', close_handler)
root.mainloop()

Closing the main window brings up the askstring dialog. *When run on OS X* (Yosemite, default Python and Tkinter version), each key press on the dialog's input field is doubled (thus when typing "abc" what will actually be entered is "aabbcc"). On Linux (Python + Tkinter 2.7.8) the problem does not occur. When the dialog is invoked from outside the close handler, the problem does not occur.

This bug is causing a downstream issue in the "quicksafe" system (https://github.com/p-e-w/quicksafe/issues/2).

ned-deily commented 9 years ago

By default Python, do you mean the Apple supplied Python in /usr/bin? If so, it uses an old Apple supplied Tk 8.5. Can you reproduce the problem with the current python.org 2.7.9 with the current ActiveState Tk 8.5 installed?

b90121a8-fbda-4f47-80a0-100dacdabbfb commented 9 years ago

I upgraded to Python 2.7.9 and ActiveTcl 8.5.17.0 as suggested. I confirmed that this is the Tk version actually used by looking at Python's About dialog. The problem persists.

ned-deily commented 9 years ago

The test case appears to only fail with OS X Cocoa Tk (tested with Tk 8.5.17 and 8.6.3); it does not fail with the older OS X Carbon Tk 8.4.20 nor with X11 Tk 8.6.3. It also fails similarly with Python 3.4.x. FWIW, there have been other reported problems with Tkinter SimpleDialog functions using Cocoa Tk, for example bpo-16023, and a number of other issues unique to Cocoa Tk. These kinds of problems are usually not simple to analyze, requiring tracing events through Tkinter and Tk and possibly lower-layer OS X APIs. It often helps to eliminate Python and Tkinter from the equation by trying to reproduce the problem with equivalent Tcl code in the Tcl/Tk wish shell if anyone feels up to it.