Script works in IDLE, but .py-file doesn't work

前端 未结 6 1970
误落风尘
误落风尘 2020-12-31 17:40

I have a tkinter script, which runs just fine in IDLE. However, when I double click the .py-file from Windows Explorer, the console window flashes half a second and then it

6条回答
  •  我在风中等你
    2020-12-31 18:15

    I had exactly the same problem with one of my scripts utilizing Tkinter. Adding call to mainloop() fixed the issue. See this tutorial for an example: [http://sebsauvage.net/python/gui/#import1

    In my case, in the init function I have

    def __init__(self,Width=400, Height=400):
            # Create GUI window ------------------------------            
            win = Tk()
            ...
    

    in the end of init I added:

            win.mainloop()
    

    Now it works by just running the file. Hope this helps

提交回复
热议问题