I have an application written in Tkinter. There is a menu item
'quit' that calls the function 'quit'. If 'quit' is called, it
first checks if there is unsaved data. If there is, it won't let
the application exit unless you confirm to disregard the
changes.
So far, so good.
I want the program to behave identical if the 'close' button of
the application window is clicked. I tried the code below,
using a class derived from Tk that redefines the destroy
method. That seems to work. At least on Linux.
My questions:
Is this the correct and save way to do this? Will it work on any
operating system? Shouldn't I do some event capturing instead?
(Capture the SIGTERM or SIGQUIT, sent by the Window manager to
the application.)
from Tkinter import *
import tkMessageBox
def quit():
if not changes:
root.quit()
else:
if tkMessageBox.as kyesno(_('Quit' ), _('Project is not saved. Ignore changes and quit?')):
root.quit()
class myTk(Tk):
def destroy(self):
quit()
root = myTk()
--
Peter Kleiweg L:NL,af,da,de,e n,ia,nds,no,sv, (fr,it) S:NL,de,en,(da, ia)
info: http://www.let.rug.nl/~kleiweg/ls.html 6 5738
Peter Kleiweg wrote: I want the program to behave identical if the 'close' button of the application window is clicked. I tried the code below, using a class derived from Tk that redefines the destroy method. That seems to work. At least on Linux.
My questions:
Is this the correct and save way to do this? Will it work on any operating system? Shouldn't I do some event capturing instead?
the right way to do this is to implement a WM_DELETE_WINDO W
protocol handler: http://effbot.org/tkinterbook/tkinte....htm#protocols
in your case, adding
root.protocol(" WM_DELETE_WINDO W", root.destroy)
to the right place should be enough.
(Capture the SIGTERM or SIGQUIT, sent by the Window manager to the application.)
that's signals, not events, and should not be needed. (afaik, a properly written
X Window application should shut down by itself, in response to DestroyWindow
requests from the window manager. if the window manager has to use explicit
kill signals to get rid of an application, something's wrong).
</F>
Peter Kleiweg wrote: I want the program to behave identical if the 'close' button of the application window is clicked. I tried the code below, using a class derived from Tk that redefines the destroy method. That seems to work. At least on Linux.
My questions:
Is this the correct and save way to do this? Will it work on any operating system? Shouldn't I do some event capturing instead?
the right way to do this is to implement a WM_DELETE_WINDO W
protocol handler: http://effbot.org/tkinterbook/tkinte....htm#protocols
in your case, adding
root.protocol(" WM_DELETE_WINDO W", root.destroy)
to the right place should be enough.
(Capture the SIGTERM or SIGQUIT, sent by the Window manager to the application.)
that's signals, not events, and should not be needed. (afaik, a properly written
X Window application should shut down by itself, in response to DestroyWindow
requests from the window manager. if the window manager has to use explicit
kill signals to get rid of an application, something's wrong).
</F>
Fredrik Lundh schreef op de 16e dag van de slachtmaand van het jaar 2005: Peter Kleiweg wrote:
I want the program to behave identical if the 'close' button of the application window is clicked. I tried the code below, using a class derived from Tk that redefines the destroy method. That seems to work. At least on Linux.
My questions:
Is this the correct and save way to do this? Will it work on any operating system? Shouldn't I do some event capturing instead?
the right way to do this is to implement a WM_DELETE_WINDO W protocol handler:
http://effbot.org/tkinterbook/tkinte....htm#protocols
in your case, adding
root.protocol(" WM_DELETE_WINDO W", root.destroy)
to the right place should be enough.
Yes, that works.
By the way, this example ends the program with root.destroy().
I used root.quit(). Is there a reason for using one or the other,
or does it not matter?
--
Peter Kleiweg L:NL,af,da,de,e n,ia,nds,no,sv, (fr,it) S:NL,de,en,(da, ia)
info: http://www.let.rug.nl/~kleiweg/ls.html
Fredrik Lundh schreef op de 16e dag van de slachtmaand van het jaar 2005: Peter Kleiweg wrote:
I want the program to behave identical if the 'close' button of the application window is clicked. I tried the code below, using a class derived from Tk that redefines the destroy method. That seems to work. At least on Linux.
My questions:
Is this the correct and save way to do this? Will it work on any operating system? Shouldn't I do some event capturing instead?
the right way to do this is to implement a WM_DELETE_WINDO W protocol handler:
http://effbot.org/tkinterbook/tkinte....htm#protocols
in your case, adding
root.protocol(" WM_DELETE_WINDO W", root.destroy)
to the right place should be enough.
Yes, that works.
By the way, this example ends the program with root.destroy().
I used root.quit(). Is there a reason for using one or the other,
or does it not matter?
--
Peter Kleiweg L:NL,af,da,de,e n,ia,nds,no,sv, (fr,it) S:NL,de,en,(da, ia)
info: http://www.let.rug.nl/~kleiweg/ls.html
Sure, there's a difference. Consider how this program behaves.
Quit only quits the mainloop, Destroy destroys the root widget.
When you Quit, you can enter the mainloop again.
from Tkinter import *
t = Tk()
Button(t, command=t.quit, text="Quit").pa ck()
Button(t, command=t.destr oy, text="Destroy") .pack()
t.mainloop()
t.mainloop()
Jeff
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFDe+NGJd0 1MZaTXX0RAu3KAK CjY0CWP4SzUu62t RbF30ZBPK5cZgCe LpFS
R/MObbYxellLtBGnD iBQzlQ=
=TKbC
-----END PGP SIGNATURE-----
Sure, there's a difference. Consider how this program behaves.
Quit only quits the mainloop, Destroy destroys the root widget.
When you Quit, you can enter the mainloop again.
from Tkinter import *
t = Tk()
Button(t, command=t.quit, text="Quit").pa ck()
Button(t, command=t.destr oy, text="Destroy") .pack()
t.mainloop()
t.mainloop()
Jeff
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFDe+NGJd0 1MZaTXX0RAu3KAK CjY0CWP4SzUu62t RbF30ZBPK5cZgCe LpFS
R/MObbYxellLtBGnD iBQzlQ=
=TKbC
-----END PGP SIGNATURE----- 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: srijit |
last post by:
Hello,
Any idea - why the following code crashes on my Win 98 machine with
Python 2.3? Everytime I run this code, I have to reboot my machine.
I also have Win32all-157 installed.
from Tkinter import *
class App:
|
by: ³Â Ñô |
last post by:
I write a program with Python 2.4 + Tkinter
Execute it, there will be a window show something.
If I minimize it, it will be minimized to the taskbar. But I would like
it to miniminze to the System Tray, this can make taskbar more clear. Would
you please tell me how to modify my program.
Thanks a lot !!
Soure Code :
|
by: Wxlu.Estes |
last post by:
Hello,
We sent you an email a while ago, because you now qualify
for a much lower rate based on the biggest rate drop in years.
You can now get $325,000 for as little as $615 a month!
Bad credit? Doesn't matter, low rates are fixed no matter what!
Follow this link to process your application and a 24 hour approval:
|
by: Peter Kleiweg |
last post by:
I have an application written in Tkinter. There is a menu item
'quit' that calls the function 'quit'. If 'quit' is called, it
first checks if there is unsaved data. If there is, it won't let
the application exit unless you confirm to disregard the
changes.
So far, so good.
I want the program to behave identical if the 'close' button of
the application window is clicked. I tried the code below,
| |
by: sandip desale |
last post by:
Dear All,
We have a Tcl/Tk application written using Python 2.2. Using this application we want to call some customizable Java APIs. I tried porting Tcl/Tk application to Jython but not able to do the same as TKinter library is not available with JYthon.
Can you please help me in porting Tkinter application to Jython? Also kindly let me know how to do the same.
Thanks & Regards,
Sandip Desale
|
by: Chris |
last post by:
Hi,
I'm puzzled by some strange behavior when my Python/Tkinter
application quits (on linux): the terminal from which I started Python
is messed up.
If start up python, then import the code below, then start the program
with Application(), then click the Quit button, my terminal never
prints anything again (such as commands I type).
|
by: Kevin Walzer |
last post by:
I'm porting a Tkinter application to wxPython and had a question about
wxPython's event loop.
The Tkinter app provides a GUI to a command-line tool. It gathers user
input, and opens an asynchronous pipe to the external tool via
os.popen(). Then, it dumps the output from the external process into a
text display. Although threads are often recommended for use with GUI
apps, I am able to keep the GUI responsive with Tkinter's event loop,...
|
by: Thomas Ploch |
last post by:
Hello folks,
I already found some answers on the net, which said that the Tk library
that Tkinter wraps does not offer functionality to minimize an
application to the system tray.
But I hope there are some wizards in here that might tell me that how
it (possibly) could be done.
Thomas
|
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...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |