Matplotlib figures not working after Tkinter file dialog

别等时光非礼了梦想. 提交于 2019-12-12 13:18:45

问题


I'm using the following function which I found as a reply to this question to show a dialog window for file selection.

[ Edit: Turns out the distro differences here are merely because Matplotlib is using gtk3agg on Fedora and TkAgg for drawing windows on each system ]

On Fedora 18: Everything works fine.

On Ubuntu 12.10: Matplotlib hangs after closing any figure displayed after the file dialog. For example, in the code below, on Ubuntu I can never get to the "made it" line. I am still able to type in the terminal, though nothing happens. If I remove the file dialog, Matplotlib figures work as expected.

import Tkinter, tkFileDialog
import pylab

def ask_for_config_file():

    print "Please provide location of configuration file."

    root = Tkinter.Tk()
    root.withdraw()
    file_path = tkFileDialog.askopenfilename()

    return file_path


def main():

    config_file_path = ask_for_config_file()

    pylab.figure()
    pylab.show()

    print "Made it."

Any suggestions?


回答1:


I just needed a root.destroy() at the end of the dialog function!



来源:https://stackoverflow.com/questions/17435360/matplotlib-figures-not-working-after-tkinter-file-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!