简体   繁体   中英

Window is not showing up at all in VSCode (tkinter)

I'm trying out tkinter in Visual Studio Code and there is no window showing up for this code (just testing):

from tkinter import * 
Tk()

Did I miss any installations?

Using Tk() alone will only create an instance of the frame, you need the mainloop() option to keep the application object in a loop.

Try this code:

import tkinter
window = tkinter.Tk()

window.title('Hello Python')
window.geometry("300x200+10+20")
window.mainloop()

have you done the installation? if you haven't done the tkinter installation, this is installation guide

for windows :

  1. To create a new Conda Python environment named <env_name> and install python 3.8, open an Anaconda Prompt or terminal and enter:

    $ conda create --name <env_name> python=3.8

  2. To activate the new environment that has Python 3.8, and switch to it, enter:

    $ activate <env_name>

To verify whether Tkinter is installed ready to be loaded by Python, run the following code in a Python console:

>>> import tkinter
>>> tkinter._test()

src: https://www.activestate.com/resources/quick-reads/how-to-install-tkinter-in-windows/

for mac :

  1. Make sure Python and pip is preinstalled on your system

to check python version :

python --version

to check pip :

pip -V
  1. Install Tkinter

    pip install tk

This command will start downloading and installing packages related to the Tkinter library. Once done, the message of successful installation will be displayed.

src :https://www.tutorialspoint.com/how-to-install-tkinter-in-python

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM