python / python/cpython

tkinter.simpledialog: KeyError when a dialog is opened while a window not created by tkinter holds the grab

未關閉
#157,676 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

stdlib topic-tkinter type-bug
主要語言
Python
星號
77.2k
分支
35.9k
PR 合併指標
PR 指標待擷取

描述

Bug report

simpledialog.SimpleDialog.go() and Dialog use _temp_grab_focus(), which calls grab_current() and focus_get() to restore the previous grab and focus afterwards. Both convert the Tcl window name with _nametowidget(), which raises KeyError for windows which were not created by tkinter, such as the native message box (.__tk__messagebox) or Tk's file dialogs on X11.

import tkinter
from tkinter import messagebox, simpledialog
root = tkinter.Tk()
root.after(300, lambda: simpledialog.SimpleDialog(root, text='hi', buttons=['OK']).go())
messagebox.showinfo('t', 'm', parent=root)
KeyError: '__tk__messagebox'

This happens in IDLE when a dialog is opened from an event delivered while a message box is shown (#153481). Regression from #151848 (3.16).

Linked PRs
  • gh-157677

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

先閱讀 tkinter.simpledialog.SimpleDialog.go()、Dialog 和 _temp_grab_focus(),然後執行提供的 messagebox 和 simpledialog 重現程式碼。當非 tk 視窗持有 grab 時開啟對話框不再引發 KeyError,且先前的 grab 和 focus 獲得還原時,修正就完成了。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
desktop
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
描述清楚
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。