python函数调用键盘热键_在Python 3中使用tkinter的键盘快捷键

Keyboard events are sent to the widget that currently owns the

keyboard focus. You can use the focus_set method to move focus to a

widget:

捕获键盘事件

from Tkinter import *

root = Tk()

def key(event):

print "pressed", repr(event.char)

def callback(event):

frame.focus_set()

print "clicked at", event.x, event.y

frame = Frame(root, width=100, height=100)

frame.bind("", key)

frame.bind("", callback)

frame.pack()

root.mainloop()

If you run this script, you’ll find that you have to click in the

frame before it starts receiving any keyboard events.

我按照本指南实现了一个ctrl f绑定到我之前的一个函数:

toolmenu.add_command(label="Search Ctrl+f", command=self.cntrlf)

root.bind('', self.searchbox)

def cntrlf(self, event):

self.searchbox()

对于您的文件菜单,您可能需要考虑实施加速器:

menubar.add_cascade(label="File", menu=fileMenu)

fileMenu.add_command(label="Exit", command=quit, accelerator="Ctrl+Q")

config(menu=menubar)

对于菜单选项,请记住使用ALT后跟OptionName的第一个字母

file Menu = ALT后跟f

工具菜单= ALT后跟t

等等

希望这提供有用的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值