473,722 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.mainloo p() #or Tkinter.mainloo p()

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._r ootframe) #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.se arch)
....
self.search_btn .pack(side='rig ht')
....
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('<Cont rol-c>')

def rClick_Cut(e):
e.widget.event_ generate('<Cont rol-x>')

def rClick_Paste(e) :
e.widget.event_ generate('<Cont rol-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(No ne, tearoff=0, takefocus=0)

for (txt, cmd) in nclst:
if txt == ' ------ ':
rmenu.add_separ ator()
else:
rmenu.add_comma nd(label=txt, command=cmd)

rmenu.entryconf igure(0, state = 'disabled')

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

except Tkinter.TclErro r:
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='<Butt on-3>',
func=rClicker, add='')
except Tkinter.TclErro r:
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 5367
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
3275
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 with this problem. I am uncertain about what etiquette calls for, but more on that later. My Objective: I am trying to control the _VMWare Desktop_ application
31
2741
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, GTK or Qt-based). A web application will not do it (although I would love it). To make a long history short: I used to develop business apps for a living for a long time (up to the mid 90s). My last experiences were with Delphi and VB. I know...
17
2807
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 it is another matter. How do you people document your access apps? Just create an ERD and have comments in the vba code? List all the forms and it's purpose ? Are there any methodologies / best practices / examples I can look at? thanks in...
5
5247
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, which scares me!) but to be installed on the start menu, it seems I don't have permission to call CheckForUpdate()! I understand that if I'm not a full trust app, I can't read the filesystem etc., but not being able to update myself seems a bit...
0
1365
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 space, without refering to using some other kind of custom control. Its for a calendar that is data bound with items which are what I want the submenu options on (or even just a different action on right click). I have divs on the form. This...
1
1124
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 procedures to start the applications. Everything works fine. When an app is started, a Process variable is used to keep track of it. I define it like this: Private WithEvents Process1 As Process When the process starts I make visible a button...
20
2024
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 developers will encounter when coming from the world of dedicated applications (VB, Delphi, etc.) I'm thinking of issues specific to web apps like the statelessness of HTTP, dealing with the back button, etc.
14
3883
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. Having a background in Pascal and some C++, I would have preferred those languages, but VBA made do. The SQL was fine. I believe that Security issues on the backend, and data integrity/ corruption complaints over the network may be a stumbling...
5
3022
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 number of options, you choose an option and then do something. Traditionally I would set up a loop - waiting for the Exit option - and, say, create database records, update them or delete them. This would make my Main() look a bit 'procedural',...
0
8863
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8739
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9238
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9157
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9088
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6681
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4502
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.