954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Using Fkeys as input?

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

pyguy62
Posting Whiz
353 posts since Aug 2011
Reputation Points: 34
Solved Threads: 19
 

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

pyguy62
Posting Whiz
353 posts since Aug 2011
Reputation Points: 34
Solved Threads: 19
 
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).

Gribouillis
Posting Maven
Moderator
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691
 

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."

pyguy62
Posting Whiz
353 posts since Aug 2011
Reputation Points: 34
Solved Threads: 19
 
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

Gribouillis
Posting Maven
Moderator
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691
 

Perfect, thank you!

pyguy62
Posting Whiz
353 posts since Aug 2011
Reputation Points: 34
Solved Threads: 19
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: