473,322 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

rlght click menu missing in most Tk apps

here is some code to add right click context menus.
in the few apps I've edited sofar, it just works, once
you run rCbinder with the root of the gui or bind B3
all present and future widgets will have right click.

there will be a line something like
root=Tk.mainloop() #or Tkinter.mainloop()

in epydoc it was necessary to look into the gui class
and find one of the attributes has the root.
add this before the root= line at the same indentation.
rCbinder(gui._rootframe) #or root or whatever
gui.mainloop() #or root. or= or whatever .|=

hopefully authors or dedicated users of Tk apps will see how simple
it is to add this basic service and will add the code themselves.
in Qt you get rightclick menu's for free with all entry widgets.
for gtk and wx, I don't know, probably is similar to one or the other.

in pydoc it was necessary to add a search button also
bind like the <return> in the Entry widget
so pydoc could be entirely mouse driven.
self.search_btn = Tkinter.Button(self.search_frm,
text='search', pady=0, command=self.search)
....
self.search_btn.pack(side='right')
....
self.search_ent.bind('<Button-3>',rClicker, add='')
self.result_lst.bind('<Button-3>',rClicker, add='')
in pydoc there are only 2 entry widgets so it
was simpler to just bind them to rClicker directly
rClicker takes an event as a parameter as default.
if I ever get a sourceforge id I will post a patch.

I found some of the original clues in Idle, which
for unknown reasons doesn't provide rightclick copy & paste.
I wouldn't take the lack of outcry as confirmation that
noone is missing this basic expected convenience.
you should assume some people think your app is broken
and possibly have quit using and recommending it.
certainly they rclick numerous times and are annoyed when
nothing familiar happens.
You can get fancy and disable or remove choices like don't
display cut or delete where they don't make sense.
you can add application specific shortcuts too, per widget,
by checking the event._name attribute or type,
you do name your widgets don't you?
adding cascading menus is just like for pulldown menus.
I've left all that out to simplify and shorten this posting.

here are the 2 functions to add-------------
def rClicker(e):
''' right click context menu for all Tk Entry and Text widgets
'''
import Tkinter
try:
def rClick_Copy(e, apnd=0):
e.widget.event_generate('<Control-c>')

def rClick_Cut(e):
e.widget.event_generate('<Control-x>')

def rClick_Paste(e):
e.widget.event_generate('<Control-v>')

e.widget.focus()

nclst=[
(' ',None), #
(' Cut', lambda e=e: rClick_Cut(e)),
(' Copy', lambda e=e: rClick_Copy(e)),
(' Paste', lambda e=e: rClick_Paste(e)),
]

rmenu = Tkinter.Menu(None, tearoff=0, takefocus=0)

for (txt, cmd) in nclst:
if txt == ' ------ ':
rmenu.add_separator()
else:
rmenu.add_command(label=txt, command=cmd)

rmenu.entryconfigure(0, state = 'disabled')

rmenu.tk_popup(e.x_root-3, e.y_root+3,entry="0")

except Tkinter.TclError:
print ' - rClick menu, something wrong'
pass

return "break"

def rClickbinder(r):
import Tkinter
try:
for b in [ 'Text', 'Entry', 'Listbox', 'Label']: #
r.bind_class(b, sequence='<Button-3>',
func=rClicker, add='')
except Tkinter.TclError:
print ' - rClickbinder, something wrong'
pass

#I don't know this is the best way to go. but,
#don't let the perfect be the enemy of the good enough
#e
__________________________________________________ ______________
The best thing to hit the Internet in years - Juno SpeedBand!
Surf the Web up to FIVE TIMES FASTER!
Only $14.95/ month - visit www.juno.com to sign up today!

Jul 18 '05 #1
1 5328
On Wed, 31 Mar 2004 22:09:57 -0500, eltronic wrote:
here is some code to add right click context menus.
in the few apps I've edited sofar, it just works, once
you run rCbinder with the root of the gui or bind B3
all present and future widgets will have right click.


how about a little example app showing how it is used?

thanks
S

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: zapazap | last post by:
Dear Snake Charming Gurus, (Was: http://mail.python.org/pipermail/python-list/2004-January/204454.html) First, a thank you to Tim Golden, Thomas Heller, and Mark Hammond for your earlier help...
31
by: Carlos Ribeiro | last post by:
Hello all. I'm in the process of writing a business app in Python. (defining business app: data entry, validation, interactive reports, etc). For my purposes, it must be a native app (wxWidgets,...
17
by: Jelmer | last post by:
Hi, I am mildly familiar with ms access developement and I have been asked to port and document a ms access app. I expect the porting (97 to XP) to be fairly straightforward. However documenting...
5
by: Danny Tuppeny | last post by:
I've been playing around with ClickOnce today, and it's all good stuff. Except, that if I change my application to NOT be full trust (which seems to make very little difference to the user prompt,...
0
by: Antoine | last post by:
I havent got room on an aspx forms data items but want to have an alternate option to double click on its link (like a right click context menu) so make the most of functionality with the lack of...
1
by: Paul | last post by:
I have a form that functions as a menu. It starts various applications and keeps track of those apps on whether they are open or not. I have used both the Shell and Diagnostics.Process.Start...
20
by: Vincent Delporte | last post by:
Hello I'm about to write a prototype for a business application, but since this my first real web application, I'm looking for a good book or article that sums up the different issues web...
14
by: ApexData | last post by:
I am considering building some distributable commercial applications. For about a year now, I have been using Access2000. This was my first venture into object oriented database development. ...
5
by: =?Utf-8?B?UGFvbG8=?= | last post by:
I'm learning C# via console apps (to avoid getting bogged down in Windows stuff). I'm wondering how the OO paradigm would work. Say I'm developing 'classic' menu-driven apps where a menu gives a...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.