destroying a Toplevel tk window in python

Tags: tkinter python
Question!

I was trying to write code that would auto-close a Toplevel Tk window in Python.

I ended up getting it to work, but ran into a little problem along the way that I wasn't able to figure out.

The second two buttons work, but the first one doesn't and I don't understand why...

Any ideas?

from Tkinter import *

root = Tk()
def doDestroy ():
    TL.destroy()

TL = Toplevel()
TL.b = Button (TL, text="lambda destroy", command=lambda: TL.destroy)
TL.b.pack()

TL.b2 = Button (TL, text="callback destroy", command=doDestroy)
TL.b2.pack()

de = lambda: TL.destroy()
TL.b3 = Button (TL, text="lambda that works", command=de)
TL.b3.pack()
root.mainloop()
By : Hortitude


Answers

Because it returns a function and not its result.

You should put:

command=TL.destroy

or if you used lambda:

command=lambda: TL.destroy()


The problem is that you need to check the reCAPTCHA before you display the form again. The PHP code would go above the first line of the form, perferrably before any HTML is generated so the user can be redirected to a thank you page.



Do note that there is no standard way to set DF in C. On Linux, this code works:

result = setsockopt(mysocket, IPPROTO_IP, 
                IP_MTU_DISCOVER, IP_PMTUDISC_DO, sizeof(int));

but it does not on FreeBSD 6

Also, Path MTU discovery is extremely unreliable on the real Internet. Too many broken firewalls and middleboxes filter out ICMP "Packet too big" messages (here is a good way to test a candidate network administrator during an interview: ask him/her to stop ping and he/she will probably block completely ICMP.) See RFC 2923: "TCP Problems with Path MTU Discovery"

That's the reason why the IETF now suggest a new way to test the MTU, without relying on Path MTU Discovery: RFC 4821: "Packetization Layer Path MTU Discovery"



This video can help you solving your question :)
By: admin