Cannot start Tkinter window in Visual Studio using Python tools

I am developing using Python Tools for Visual Studio in the Visual Studio 2013 community version on Windows 8.1. My problem is that I cannot start the Tkinter window. I tried using this code:

from tkinter import * Tk() 

When I run this code from IDLE and this way I can get the tkinter window as shown:

tkinter in idle

However, when I run this in Visual Studio, the Tkinter window does not appear, but only the console window. An error does not occur. Example:

tkinter in vs

How do I get the Tkinter window that appears when a program starts in Visual Studio using Python tools?

Edit: Also, when I try to do this from a Python interactive window in VS, this is what I get without the window appearing:

 >>> from tkinter import * >>> Tk() <tkinter.Tk object at 0x02D81FD0> 
+6
source share
1 answer

Most likely, the problem is that you are not starting the event loop. Without an event loop, the program will exit immediately. Try changing your program like this:

 import tkinter as tk root = tk.Tk() root.mainloop() 

The reason you don't need to call mainloop in IDLE is because IDLE does this for you. In all other cases, you must call mainloop.

+1
source

Source: https://habr.com/ru/post/978997/


All Articles