So I was writing a short code to test something when I noticed this interesting behaviour.
import tkinter
from tkinter import *
master=tkinter.Tk()
master.geometry("800x850+0+0")
master.configure(background="lightblue")
def d():
master.destroy()
button=Button(master, text="asdf", command=d).pack()
master.mainloop()
The button closes the window as expected, but when I click on the red button on the top left button (from the actual window, not tkinter), the program gets stuck and doesn't respond. However, when I change the code to remove the text in the button as follows:
import tkinter
from tkinter import *
master=tkinter.Tk()
master.geometry("800x850+0+0")
master.configure(background="lightblue")
def d():
master.destroy()
button=Button(master, command=d).pack()
master.mainloop()
It now works perfectly fine. Both the tkinter button in the window and the red button from the actual window close the window as expected. Why does this happen? I am using python 3.5 on Mac, in case this matters.
button=Button(master, text="asdf", command=d)
and next line:button.pack()
? It should work fine though, and so it does on my system (Ubuntu 16.04) – Jacob Vlijm