how to bind keys to menu items?

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2006
Posts: 237
Reputation: katharnakh is an unknown quantity at this point 
Solved Threads: 33
katharnakh's Avatar
katharnakh katharnakh is offline Offline
Posting Whiz in Training

how to bind keys to menu items?

 
0
  #1
Feb 10th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,221
Reputation: bumsfeld will become famous soon enough bumsfeld will become famous soon enough 
Solved Threads: 138
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Nearly a Posting Virtuoso

Re: how to bind keys to menu items?

 
0
  #2
Feb 10th, 2006
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.
  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()
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC