is it possible to use the Fkeys, i.e. F1, F2,...F12, as input in any way?

Recommended Answers

All 5 Replies

I'm guessing the only way to do this is with some third party modules?

I'm guessing the only way to do this is with some third party modules?

You can use them with the GUI toolkits (eg Tkinter).

does it say how in the documentation? I tried that with an Entry(self) and when I tried stating if the variable I had assigned to it == F1 "how ever I hit the F1 button" nothing happened, it just wouldn't accept the input from the key "while writing the program, not user end."

does it say how in the documentation? I tried that with an Entry(self) and when I tried stating if the variable I had assigned to it == F1 "how ever I hit the F1 button" nothing happened, it just wouldn't accept the input from the key "while writing the program, not user end."

Here is an exemple, adapted from an old forum post, to show you how to bind the F1 key

from functools import partial
from Tkinter import *

def fonction(text, event):
    text.insert(END,'ok ')

def bind(wid):
    wid.bind('<F1>',partial(fonction, wid))

def unbind(wid):
    wid.unbind('<F1>')

root = Tk()
text = Text(root)
text.pack()
b1 = Button(root,text="Bind",command=partial(bind, text))
b2 = Button(root,text="Unbind",command=partial(unbind, text))
b1.pack()
b2.pack()
b1.invoke()
text.focus_set()
root.mainloop()

Also read this http://www.pythonware.com/library/tkinter/introduction/events-and-bindings.htm

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.