944,084 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 6030
  • Python RSS
Feb 10th, 2006
0

how to bind keys to menu items?

Expand Post »
how to bind keyboard keys to menu items? i know to bind with mouse buttons but with keybooard keys dont know.
for eg: Cntl+O to open a file in File menu.

how to implement undo, redo, find, find again, copy, paste functions in python. i actually gone through the IDLE.py, which is shipped with python package, but it is such big code i couldnt trace it. can any body breif about how implement this in python?

please help me out.
Similar Threads
Reputation Points: 19
Solved Threads: 34
Posting Whiz in Training
katharnakh is offline Offline
237 posts
since Jan 2006
Feb 10th, 2006
0

Re: how to bind keys to menu items?

I hope you are talking about Tkinter as GUI. This code might help you. You have to use a if statements to get the right key value to go to the proper function then.
Python Syntax (Toggle Plain Text)
  1. # bind and show a key event with Tkinter
  2.  
  3. from Tkinter import *
  4.  
  5. root = Tk()
  6. prompt = ' Press any key '
  7. label1 = Label(root, text=prompt, width=len(prompt))
  8. label1.pack()
  9.  
  10. def key(event):
  11. if event.char == event.keysym:
  12. msg = 'Normal Key %r' % event.char
  13. elif len(event.char) == 1:
  14. msg = 'Punctuation Key %r (%r)' % (event.keysym, event.char)
  15. else:
  16. msg = 'Special Key %r' % event.keysym
  17. label1.config(text=msg)
  18.  
  19. label1.bind_all('<Key>', key)
  20.  
  21. root.mainloop()
Reputation Points: 404
Solved Threads: 180
Nearly a Posting Virtuoso
bumsfeld is offline Offline
1,422 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Thread Dump of a python process
Next Thread in Python Forum Timeline: GUI for Python





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC