Skip to content

A bug when bind <F3> shortcut key in the Tkinter program. #146030

@thefatwhale

Description

@thefatwhale

Bug report

Bug description:

On the Windows 10, if you input an "r" using the Chinese PinYin input method. then press the Enter key to display the English "r" on the text box, it will trigger the F3 input event.

also on IDLE (It is also a built-in program developed based on tkinter).
When using the idle program, if you input "r" and make it appear on the screen, it will cause the "Find and Replace" dialog box to be displayed. Equals to Press the F3 key.

this is minimal example code of this bug.

test on:
Windows 10 + Python 3.10.11
Windows 10 + Python 3.14.3

# minimal example code

import tkinter as tk

def on_f3_press(event):
    print("-" * 30)
    print("【trigger】F3 event!")
    print(f"keysym: {event.keysym}")
    print(f"char: {event.char}")
    print(f"keycode: {event.keycode}")
    print(f"type: {event.type}")
    print("-" * 30)


# 创建主窗口
root = tk.Tk()
root.title("Tkinter F3 Bug 复现测试")
root.geometry("400x400")

# 创建一个输入框
entry = tk.Entry(root, width=50, font=("Arial", 14))
entry.pack(pady=20, padx=20)

# 创建一个文本区域
text = tk.Text(root, height=10, font=("Arial", 12))
text.pack(pady=10, padx=20)

# 核心关键:绑定 F3 快捷键
# 我们在根窗口级别绑定,这样无论焦点在哪都能捕获
root.bind("<Key-F3>", on_f3_press)

label = tk.Label(root, text="请使用输入法在框中输入字母 'r' 并回车上屏。\n如果控制台打印了信息,则说明 Bug 复现成功。", wraplength=350, justify="left")
label.pack(pady=20)

root.mainloop()
python demo.py

use IME such as Chinese input method on Windows

------------------------------
【trigger】F3 F3 event!
keysym: F3
char: r
keycode: 114
type: 2
------------------------------

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-windowsstdlibStandard Library Python modules in the Lib/ directorytopic-tkintertype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions