How do I display and close an image with Python?

后端 未结 5 724
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-12 04:08

I would like to display an image with Python and close it after user enters the name of the image in terminal. I use PIL to display image, here is the code:

         


        
5条回答
  •  佛祖请我去吃肉
    2021-01-12 04:37

    Terminal is meant to deal with linear command flow - meaning it asks a question, user answers, and then it can ask a different question. What you are trying to do here is for terminal to do two things, show an image and at the same time ask user a question. To do this you can do two of either things:

    Multiprocessing

    You can start a new thread/process and make PIL show the image using that thread, and meanwhile in the first thread/process ask a user a question. Then after the user answers, you can close the other thread/process. You can take a look at Python's threading module (link) for more information on how you can do that.

    GUI

    Instead of making your user interface in terminal, make a simple GUI application using whatever framework you are comfortable. I personally like PyQt4. Qt is very powerful GUI development toolkit and PyQt4 is a wrapper for it. If you make a GUI, then what you are tyring to do is rather trivial.

提交回复
热议问题