I'm building an application involving both twisted and Tkinter. Since
twisted co-opts <widget>.mainlo op() 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_bi nd(x):
reactor.stop()
Then:
root.bind('<Des troy>',stop_rea ctor_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? 4 5597
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)
iD8DBQFCq5suJd0 1MZaTXX0RAjCsAK CopeOFSbNIatjYu pztNlln57j6UwCd Hquu
+QmRYrRlpBvfP0/5w9GZ3E4=
=7+oL
-----END PGP SIGNATURE----- je****@unpython ic.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]
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("<Destro y>", 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)
iD8DBQFCrDc0Jd0 1MZaTXX0RAt/vAJwPoBlfbHEXuF 4ppeFVyDiWuI71F wCeJc/K
wIY45XQ2F9mtqfC H+cR/oC4=
=MHOq
-----END PGP SIGNATURE-----
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! :) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 outer
frame.
Andrew.
# Demonstration TK interface Windows application
# Runs ok from within IDLE
|
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 function then initially calls another function to
"root.destroy()". Basically I want the current window gone so the function I
just called can open it's own window. The problem I'm stuck with is that
once this function is done and I need to close...
|
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, QuickTimeMovie, that would wrap up the QuickTimeTcl
Tcl extension as a Python class. All seems to work pretty fine until the
Tkinter application is closed, when the Python interpreter crashes with an
error of the following kind:
The instruction at...
|
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 script as a
bunch of asynchronously called subroutines).
I decided to use Tkinter's wait_variable. I built a "script runner"
object that has suitable wait methods. Internally each of these methods
registers a callback that sets a variable when...
|
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 still exists and has a tkinter
name, so testing for None is not feasible:
>>> import Tkinter
>>> fin = None
>>> fin1 = Tkinter.Toplevel()
| |
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.
My code writes to a text file 'table.txt', and 'table.txt' is displayed
in
|
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 window. Is
this expected, and can I avoid this?
To expose the problem, run this script and click the mouse button over
the application window. When the file save dialog is through, the
function "callback" is called, which I did not expect because...
|
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
this I mean that the format would be something like this:
You have Page1 : This has 2-3 buttons on it.
Clicking on each button opens up a new window respectively having
|
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 from Tkinter.py)
class Tk(Misc, Wm):
"""Toplevel widget of Tk which represents mostly the main window
of an appliation. It has an associated Tcl interpreter."""
_w = '.'
def __init__(self, screenName=None, baseName=None,...
|
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...
|
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,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |