473,320 Members | 2,000 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,320 software developers and data experts.

TKinter -- '<Destroy>' event executing more than once?

I'm building an application involving both twisted and Tkinter. Since
twisted co-opts <widget>.mainloop() in its reactor.run(), and since it
behaves very badly if the application quits without reactor.stop()
running, I attach the following function to '<Destroy>' in the main
window (root = Tk()):

def stop_reactor_bind(x):
reactor.stop()

Then:
root.bind('<Destroy>',stop_reactor_bind)

The problem, however, comes that when I add a Text widget inside the
root window, upon destroying the window (closing it) the callback seems
to execute twice. In interactive testing, it's executed once per widget
inside the root window. Since twisted doesn't take multiple
reactor.stop()s gracefully, how (short of wrapping this inside a
class/scope that keeps state) can I ensure that the callback executes
only once? Am I attaching to the wrong signal?
Jul 19 '05 #1
4 5441
Bindings created on a Toplevel or Tk widget apply to *all* widgets in the same
toplevel.

So you're seeing a <Destroy> event for each widget you create...

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFCq5suJd01MZaTXX0RAjCsAKCopeOFSbNIatjYupztNl ln57j6UwCdHquu
+QmRYrRlpBvfP0/5w9GZ3E4=
=7+oL
-----END PGP SIGNATURE-----

Jul 19 '05 #2
je****@unpythonic.net wrote:
Bindings created on a Toplevel or Tk widget apply to *all* widgets in
the same toplevel. So you're seeing a <Destroy> event for each widget
you create...


Oh. :) Is there a way of binding the event just to the window itself,
or should I just check that the widget referenced in the 'event'?
[update: not even sure how I'd do this anyway, since the widget returned
in the event "is not" the root widget]
Jul 19 '05 #3
For me, an 'is' test works to find out what widget the event is taking
place on.

#------------------------------------------------------------------------
import Tkinter

def display_event(e):
print "event received", e.widget, e.widget is t

t = Tkinter.Tk()
t.bind("<Destroy>", display_event)
w = Tkinter.Entry(t)
t.destroy()
#------------------------------------------------------------------------

This program prints:
event received .-1209415348 False
event received . True

if that fails, you could compare str(e.widget) and t._w, though this can
give a false positive if you have multiple Tk() instances---each Tk()
instance is called ".".

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFCrDc0Jd01MZaTXX0RAt/vAJwPoBlfbHEXuF4ppeFVyDiWuI71FwCeJc/K
wIY45XQ2F9mtqfCH+cR/oC4=
=MHOq
-----END PGP SIGNATURE-----

Jul 19 '05 #4
Jeff Epler wrote:
For me, an 'is' test works to find out what widget the event is taking
place on.


.... yes, I am apparently as stupid as I look. In my test code, I was
trying "if event is widget," and I just now saw that. Thanks! :)
Jul 19 '05 #5

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

Similar topics

5
by: Andrew Gregory | last post by:
Could someone help me out with these few lines of code: I would like to know why the Quit button in this application removes the buttons and causes "Quitting" to be printed, but does not close the...
2
by: Rob | last post by:
My first GUI so be gentle... When I start my program I call a class that runs the initial window. While in this class if a certain button is pressed it calls a function outside the class. This...
3
by: Mickel Grönroos | last post by:
Hi everybody, I'm using QuickTimeTcl (3.1) to be able to play movie files in my Tkinter application (Python 2.3.2) on Windows 2000. I was planning to write a simple wrapper class,...
2
by: Russell E. Owen | last post by:
I want to support execution of simple user-written scripts in a Tkinter application. The scripts should be able to wait for data and such without hanging the GUI (and without having to write the...
6
by: max(01)* | last post by:
hi people. when i create a widget, such as a toplevel window, and then i destroy it, how can i test that it has been destroyed? the problem is that even after it has been destroyed, the instance...
1
by: C D Wood | last post by:
To whom this may concern, Below is the source code, which demonstrates a problem I am having making a GUI for my python project work. 'table.txt' is a file that is read from the same folder....
0
by: John Hunter | last post by:
The following behavior surprised me. I have a Tk window and launch a file save dialog from it. When the filesave dialog is finished, it calls callbacks bound to the destroy event on the main...
3
by: J-Burns | last post by:
Hello. Im a bit new to using Tkinter and im not a real pro in programming itself... :P. Need some help here. Problem 1: How do I make something appear on 2 separate windows using Tkinter? By...
0
by: nicstel | last post by:
Hello. My script run fine within python but not in my program(SDS/2 wich is a software like Autocad). The problem is I got an error when the time comes to read the line14 to 19. (Source code come...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
0
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.