SoFunction
Updated on 2024-11-10

Troubleshooting Turtle code in PyCharm with no prompts and yellow markers

PyCharm in the use of Turtle (Turtle) library drawing system, the code is clearly correct can run, but there is no prompt , the code appears yellow markers as well as the red wavy line, inexperienced people also think that their writing method is wrong, after all, the red wavy line, the effect is as follows:

Statement of Reasons:

Often this problem may not be your problem, but pycharm and turtle library has a conflict , can not identify themselves under the turtle method, standing in the pycharm itself under the point of view it feels that your code is wrong, can not find, so give you marked red line, marked yellow:

Solution:

Click into the source file, make the following changes to the turtle library source code, comment out the original _ all_, copy the following code, the effect is as follows

__all__ = ['ScrolledCanvas', 'TurtleScreen', 'Screen', 'RawTurtle', 'Turtle', 'RawPen', 'Pen', 'Shape', 'Vec2D',
  'back','backward', 'begin_fill', 'begin_poly', 'bk', 'addshape', 'bgcolor', 'bgpic', 'bye', 'clearscreen',
  'colormode', 'delay', 'exitonclick', 'getcanvas', 'getshapes', 'listen', 'mainloop', 'mode', 'numinput',
  'onkey', 'onkeypress', 'onkeyrelease', 'onscreenclick', 'ontimer', 'register_shape', 'resetscreen',
  'screensize', 'setup', 'Terminator', 'setworldcoordinates', 'textinput', 'title', 'tracer', 'turtles',
  'update', 'window_height', 'window_width', 'write_docstringdict', 'done', 'circle', 'clear', 'clearstamp',
  'clearstamps', 'clone', 'color', 'degrees', 'distance', 'dot', 'down', 'end_fill', 'end_poly', 'fd',
  'fillcolor', 'filling', 'forward', 'get_poly', 'getpen', 'getscreen', 'get_shapepoly', 'getturtle', 'goto',
 'heading', 'hideturtle', 'home', 'ht', 'isdown', 'isvisible', 'left', 'lt', 'onclick', 'ondrag', 'onrelease',
  'pd', 'pen', 'pencolor', 'pendown', 'pensize', 'penup', 'pos', 'position', 'pu', 'radians', 'right', 'reset',
  'resizemode', 'rt', 'seth', 'setheading', 'setpos', 'setposition', 'settiltangle', 'setundobuffer', 'setx',
  'sety', 'shape', 'shapesize', 'shapetransform', 'shearfactor', 'showturtle', 'speed', 'st', 'stamp', 'tilt',
  'tiltangle', 'towards', 'turtlesize', 'undo', 'undobufferentries', 'up', 'width', 'write', 'xcor', 'ycor']

Modify the effect:

Addendum: pycharm partially solves the problem of pycharm code without prompts Add object declarations

You python children's shoes in the daily use of pycharm in the process of whether the same encounter code without prompting the difficult situation.

The following describes a partial solution to the hint problem by means of a type declaration.

an actual example

def index(request:HttpRequest): # The formal parameter sets the type of the object, : followed by the class name.
 # Declared at variable definition
 template = loader.get_template("") # type : Template 
 () # Tested to work heretemplate Unprompted

The above is a personal experience, I hope it can give you a reference, and I hope you can support me more. If there is any mistake or something that has not been fully considered, please do not hesitate to give me advice.