import tkinter as tk
from tkinter import *
def fun():
def fun1():
print("点击响应")
def fun2(event):
print("快捷键响应")
window = tk.Tk()
menu_bar = tk.Menu(window)
window['menu'] = menu_bar
sub_1 = tk.Menu(menu_bar, tearoff=False)
sub_2 = tk.Menu(menu_bar, tearoff=False)
sub_1.add_command(label='保存', accelerator='Ctrl+S', command=fun1)
window.bind('<Control-s>', fun2)
sub_1.add_command(label='另存为', accelerator='Ctrl+Shift+S', command=fun1)
window.bind('<Control-Shift-KeyPress-S>', fun2)
sub_1.add_separator()
sub_1.add_command(label='退出', accelerator='Alt+F4', command=fun1)
window.bind('<Alt-F4>', fun2)
sub_2.add_command(label='查看帮助(H)', command=fun1)
# menu_bar.bind('<h>', fun2)
sub_2.add_separator()
sub_2.add_command(label='关于我们')
menu_bar.add_cascade(label='文件', menu=sub_1)
menu_bar.add_cascade(label='帮助', menu=sub_2)
window.mainloop()
fun()
想问一下,注释行这里,我想实现当点击菜单栏后才可以键入快捷键h,而不是在整个窗口里面,该怎么实现呢?
像图里这样没有反应