473,785 Members | 2,481 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

tkinter wm_delete_windo w

hello i want to intercept tkinter python system events like
wm_delete_windo w
and if possible for any window, but the newest code I've produced give
me
an error :

Traceback (most recent call last):
File "C:\Documen ts and Settings\yvesd\ Bureau\protowin .py", line 36,
in ?
b1 = Tkinter.Button (win1)
File "C:\Python24\li b\lib-tk\Tkinter.py", line 1933, in __init__
Widget.__init__ (self, master, 'button', cnf, kw)
File "C:\Python24\li b\lib-tk\Tkinter.py", line 1856, in __init__
BaseWidget._set up(self, master, cnf)
File "C:\Python24\li b\lib-tk\Tkinter.py", line 1834, in _setup
self.tk = master.tk
AttributeError: MyDlg instance has no attribute 'tk'

thanks a lot for the help answer.

here is my code :

import Tkinter
from Tkinter import *

class MyDlg(Toplevel) :
def ma_fonction():
print "my function is finished."
def __init__(arg1, arg2):
arg1.protocol(" WM_DELETE_WINDO W", arg1.ma_fonctio n)

root = Tkinter.Tk ()
#win1 = Tkinter.Topleve l (root)
win1 = MyDlg(root)
b1 = Tkinter.Button (win1)
b1.config (text="hello")

Jul 18 '06 #1
1 5255
On Tue, 18 Jul 2006 11:16:04 +0200, yvesd <yv************ @gmail.comwrote :
hello i want to intercept tkinter python system events like
wm_delete_windo w
and if possible for any window, but the newest code I've produced give
me
an error :
Traceback (most recent call last):
File "C:\Documen ts and Settings\yvesd\ Bureau\protowin .py", line 36,
in ?
b1 = Tkinter.Button (win1)
File "C:\Python24\li b\lib-tk\Tkinter.py", line 1933, in __init__
Widget.__init__ (self, master, 'button', cnf, kw)
File "C:\Python24\li b\lib-tk\Tkinter.py", line 1856, in __init__
BaseWidget._set up(self, master, cnf)
File "C:\Python24\li b\lib-tk\Tkinter.py", line 1834, in _setup
self.tk = master.tk
AttributeError: MyDlg instance has no attribute 'tk'
thanks a lot for the help answer.
here is my code :
import Tkinter
from Tkinter import *
Do not import the same module twice: either use "import Tkinter" and
prefix everything in it with 'Tkinter.', or use "from Tkinter import *"
and don't specify any prefix. You're mixing both here.
class MyDlg(Toplevel) :
def ma_fonction():
You must specify 'self' as first parameter here. Or put 'ma_fonction'
outside the class.
print "my function is finished."
def __init__(arg1, arg2):
arg1.protocol(" WM_DELETE_WINDO W", arg1.ma_fonctio n)
Please don't use anything else than 'self' as the name for methods' first
parameter. It will confuse everyone who knows Python. And your mistake is
here: the constructor for the super-class (Toplevel) is not called
automatically by the sub-class constructor; so you have to do it yourself.
So just rewrite these two lines as:

def __init__(self):
Toplevel.__init __(self)
self.protocol(" WM_DELETE_WINDO W", self.ma_fonctio n)

and everything should work fine. BTW, I've removed the parameter arg2 that
you didn't use at all.
root = Tkinter.Tk ()
#win1 = Tkinter.Topleve l (root)
win1 = MyDlg(root)
Replace that with:

win1 = MyDlg()
b1 = Tkinter.Button (win1)
b1.config (text="hello")
An additional small note: you can write the last two lines as a single one:

b1 = Tkinter.Button( win1, text='hello')

And you also must call:
- b1.pack, b1.grid or b1.place to put your button somewhere in your window.
- root.mainloop() in the end or your window will never appear.

If you want to do Tkinter the OO way, you may also create the button in
the dialog's constructor.

So here would be my version of your program:

----------------------------------------------
from Tkinter import *

class MyDlg(Toplevel) :
def __init__(self):
Toplevel.__init __(self)
b1 = Button(self, text='hello')
b1.pack()
self.protocol(" WM_DELETE_WINDO W", self.ma_fonctio n)
def ma_fonction(sel f):
print "my function is finished."

root = Tk()
win1 = MyDlg()
root.mainloop()
----------------------------------------------

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz 5(17l8(%,5.Z*(9 3-965$l7+-'])"
Jul 18 '06 #2

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

Similar topics

2
26259
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...
3
3344
by: DoubleM | last post by:
Hi, I'm running Python2.3.3c1 on Mandrake 9.1 The following code is designed to bring up a window with a button labeled "popup". Clicking on the popup buttons triggers a secondary window with a button labeled "ok". The second window is supposed to be modal - it should not be possible to reset the focus back to the first window or close the first window without first closing the second. The program works just fine in Windows XP...
3
2344
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...
2
3896
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...
1
2254
by: Pekka Niiranen | last post by:
Hi there, after reading TkInter/thread -recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965 I wondered if it was possible to avoid using threads for the following problem: I have script started from W2K console that normally prints ascii messages to the screen. However, I have command line "debug" -flag that might cause printing
6
5736
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,
4
2225
by: Bob Greschke | last post by:
Hi! I want to grab the contents of a Text widget when the frame it's on gets destroyed. I tried TextWidget.bind("<Destroy>"... , but the widget is gone before the call gets made, and I'd really hate to do something with the function that gets called with TextWidgetsFrame.bind("<Destroy>", ..., since that one function handles all of the frames in the program...or would that even work? How can I do this?
5
4252
by: half.italian | last post by:
Hi all, I don't really understand how to properly use threading in my programs, however I have managed to get by so far using them improperly. Once again I have come up to what I think is something that won't work because of the way the program is set up. I have a long running process running underneath a gui in a different thread, and a progress bar that updates the status of the operation. What I would like to do is use something...
0
3989
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,...
0
10325
Oralloy
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...
0
10147
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
10091
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
9950
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...
0
8972
agi2029
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...
1
7499
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
5381
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
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 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.