473,435 Members | 1,537 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,435 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 5342
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.