简体   繁体   中英

GUI does not appear when running python code with VSCode and Pycharm

I was trying to write some python code, inside my code I imported the turtle module and when I ran my code on VSCode I expected to see a GUI window but instead I got the following errors:

在此处输入图像描述

And besides that I get a Problem Report for Python showing up:

在此处输入图像描述

This is what my code looks like:

import turtle

my_turtle = turtle.Turtle()

my_turtle.shape("turtle")
my_turtle.color("red")
my_turtle.forward(100)

screen = turtle.Screen()
screen.exitonclick()

My macOS version is 11.1 btw.

Correct me if I'm wrong but apparently Python 2.7.16 does not support the Turtle module, so I switched my python version to 3.9.1 on the terminal and when I ran python main.py the GUI finally appeared.

I used the following command to switch python versions on my terminal:

alias python="python3"

Although I have solved this problem on my terminal, I have yet to see a way to change the python version on VSCode.

Perhaps you should install python 3.9.1 directly into your machine, so you don't worry about it.

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