Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 22nd, 2004, 09:17 PM
Arteum Arteum is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 4 Arteum User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Binding confusion in Tkinter

Hello, everyone :-)

And now for something completely different: I am experiencing a slight problem with binding to Shift-Return key event in Tkinter.

I am writing a front end to Python a la Mathematica's so that I might be able to display non-ASCII characters, save the contents of the window in a file etc.

I created a Text widget, in which I type the command, then press the "CALCULATE" button and the result appears on the next line. I would like to bind the action performed by the "CALCULATE" button to a sequence of keys Shift-Return, again, just as in Mathematica. This binding works (that is, calculation is done and the result is displayed after Shift-Return has been pressed), but together with a direct action of Shift-Return on text (that is, the cursor jumps to the next line).

Here's the piece of my code where the problem occurs (resides in the __init__ method):

b=Button(toolbar,text="CALCULATE",command=lambda s=self:s.calculate_bttn(text))
text.bind("<Shift-Return>",lambda event:self.calculate_bttn(text))

where "calculate_bttn(self,widget)" is a method defined in the current class.

Note that if I bind to text (just as shown above), the calculation (according to calculate_bttn(self,widget)) is performed first, and after that the line (due to Shift-Return action) is inserted. But if I bind to master (the main window), the sequence of events is reverse: first the line is inserted and then calculate_bttn(self,widget) runs.

Does anybody have any idea how to stifle the unneeded, unbinded action of Shift-Return, which makes the cursor jump to the next line?

I understand that I am probably binding to two different widgets, but I can't perceive how to solve the problem descpite already spending three hours on it.

Any help will be greatly appreciated.

Thank you.

Arteum

Reply With Quote
  #2  
Old April 23rd, 2004, 03:22 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 12
Send a message via MSN to Grim Archon
According to The Tkinter reference your event handler should return a "break" string to break the chain of handlers:

Code:
def myhandler(event):
    #do stuff
    return "break"

text.bind("<Shift-Return>",myhandler)


This should swallow the Shift-Return characters.

Grim
__________________
*** Experimental Python Markup CGI V2 ***

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Binding confusion in Tkinter

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap