I ran into a problem using tkinter and matplotlib.pyplot, that I don't understand.
Minimal example
import tkinter
import tkinter.filedialog as tk_filedialog
import numpy as np
import matplotlib.pyplot as plt
def main():
# # -- part 1 --
# tkinter.Tk().withdraw()
junk = tk_filedialog.askopenfilename()
# # -- part 2 --
x_p = np.linspace(0,10,100)
fig = plt.figure()
plt.plot(x_p,x_p,color='b')
plt.show()
print("blob")
if __name__ == '__main__':
main()
print("blab")
My implementation was originally with the line tkinter.Tk().withdraw() uncommented, but then you don't see what happens.
The program above will run but does not terminate. It should do the following steps:
- Open Tkinter "Select-File-Dialog" -> Choose any file, as it does nothing.
- Plot the curve -> Close the Plot Window
- Print "blob", print "blab"
The problem is that the Tkinter window, which would be suppressed by tkinter.Tk().withdraw(), does not close. That leads to two unexpected behaviours - see below.
The most confusing part is: If you comment either -- part 1 -- or -- part 2 -- the program will run as expected.
Winpython3.5 started from Cygwin
After closing this tkinter window "blob" and "blab" will be printed and the program terminates as expected.

Spyder 3
"blob" and "blab" are printed before closing the figure window, and before closing the tk window. Additionally it is impossible to close the tk window (the x-button does nothing). It closes with closing spyder, though.

IDLE
Same behaviour as Cygwin.
Any ideas? Did I miss some close() command for tkinter?
I found this:
tk_window = tkinter.Tk()
tk_window.destroy()
But that does not solve the problem above.
osto further reduce the example.numpycould also be thrown out of the example using a listx_p = [1,2,3]runfiledose but IPython can have issues with interactive use of GUI toolkits unless you take some care. Using two GUI toolkits in the same session can be even trickier.