Home > other >  Pycharm import pygame failure
Pycharm import pygame failure

Time:12-02



I want to write a few 2 d with pygame python syntax, meet some little game, with pygame1.9.3 pycharm installed, when using pythong3.6.1 64 pygame package is installed successfully but the result of the reference when they appeared on the graph warning found inside pygame package of classes and methods can't use

1. Pygame installed successfully, but the inside of the pygame. The init () in the following warning:
Always find a reference 'init' 'just set in py' less... (Ctrl + F1)
This inspection detects names that should resolve but don 't Due to the dynamic dispatch and duck typing, This is possible in a limited but useful number of cases in the Top - level and class - level items are supported better than instance items.

2. With pygame. Draw lines (surface, color, closed, pointlist, width) is an error:
Traceback (the most recent call last) :
The File "G:/Python/new folder/... Py ", line 17, in & lt; module>
Pygame. The draw. Lines (DISPLAYSURF, BLUE, (60, 60), (120, 60), 4)
TypeError: points must be number pairs

3. Use the QUIT time also error
The Unresolved reference 'QUIT' less... (Ctrl + F1)
This inspection detects names that should resolve but don 't Due to the dynamic dispatch and duck typing, This is possible in a limited but useful number of cases in the Top - level and class - level items are supported better than instance items.

4. Install pygame for the first time I also installed Livewires package (inherit a simple version of pygame pygame package) and some of the success of the installation method cannot reference

Baidu, a lot of sites in the BBS I see a lot of post summarizes the following possible problems
1. Pygame and python version does not match the
So I just downloaded python3.6.5 32-bit then configure pycharm interpreter into a 32 bit python, installed with pycharm pygame, problem is still not
2. May be the problem of pycharm
So I upgrade the pycharm upgrade from 2017.3 to 2018.1 and then wrapped matlotlib pycharm installed this package no problem can draw line chart
3. The problem of python version
I will upgrade the python to 3.6.5 64 relocation pycharm pygame installation problems remain
4. Pycharm Project Structure problems setting up the
Me to use the site - packages folder Settings as Sources problem still not solve the


The following is the code
The import pygame, sys
The from pygame. Locals import *

Pygame. The init ()

DISPLAYSURF=pygame. Display. Set_mode ((500, 400), a 0, 32)
Pygame. Display. Set_caption (' Drawing ')

BLACK=(0, 0, 0)
WHITE=(255, 255, 255)
RED=(255, 0, 0)
GREEN=(0, 255, 0)
BLUE=(0, 0, 255)

DISPLAYSURF. The fill (WHITE)
Pygame. The draw. Polygon (DISPLAYSURF, GREEN, ((146, 0), (291, 106), (236, 277), (56, 277), (0, 106)))
# pygame. The draw. Lines (DISPLAYSURF, BLUE, (60, 60), (120, 60), 4)
# pygame. The draw. Lines (DISPLAYSURF, BLUE, (120, 60), (60, 120))
# pygame. The draw. Lines (DISPLAYSURF, BLUE, (60, 120), (120, 120), 4)
Pygame. The draw. Circle (DISPLAYSURF, BLUE, (300, 50), 20, 0)
Pygame. The draw. The ellipse (DISPLAYSURF, RED (300, 250, 40, 80), 1)
Pygame. The draw. The rect (DISPLAYSURF, RED (200, 150, 100, 50))

Pixobj=pygame. PixelArray (DISPLAYSURF)
Pixobj [480] [380]=BLACK
Pixobj [482] [382]=BLACK
Pixobj [484] [384]=BLACK
Pixobj [486] [386]=BLACK
Pixobj [488] [388]=BLACK
Del pixobj

# the run the game loop
While True:
For the event in pygame. Event. The get () :
If the event type==the QUIT:
Pygame. Quit ()
Sys. The exit ()
Pygame. Display. The update ()


If the pygame. The draw. Lines () that run a few line commented out the program will also be able to normally closed (but QUIT and pygame. QUIT () error, obviously should not normally closed)

From the found problems to get back and forth for a week now, no solved problems really maddening!

CodePudding user response:

Pygame. The draw. Lines (DISPLAYSURF, BLUE, True, ((120, 60), (60, 60), 4)
Pygame. The draw. Lines (DISPLAYSURF, BLUE, True, ((120, 60), (60, 120)), 4)
Pygame. The draw. Lines (DISPLAYSURF, BLUE, True, ((60, 120), (120), 120), 4)
The two point here is to use a tuple to the parcel

CodePudding user response:

Pygame. The draw. Lines

Prototype: pygame. The draw. Lines (Surface, color, closed, pointlist, width=1) : return the Rect

Purpose: to draw a series of straight line segments and closed is a Boolean variable, if closed is true, then according to the need to connect the first and the last point, the point came from pointlist, a list containing the coordinates, to the end of this function does not draw Lines, there is no bevel connection (miter joints), and small Angle and line thick cords will look a bit odd (Lines with sharp corners and wide line widths can have improper & corners.),

CodePudding user response:

CodePudding user response:

reference 1/f, Py full stack engineer reply:
pygame. The draw the lines (DISPLAYSURF, BLUE, True, ((120, 60), (60, 60), 4)
Pygame. The draw. Lines (DISPLAYSURF, BLUE, True, ((120, 60), (60, 120)), 4)
Pygame. The draw. Lines (DISPLAYSURF, BLUE, True, ((60, 120), (120), 120), 4)
The two point here is to use a tuple to packages

. Oh, oh, I think I put the draw lines () and draw the line confused

CodePudding user response:

Py
reference 3 floor full stack engineer reply:

Yes, I can run out this figure
But pycharm complains,,,,

CodePudding user response:

Solve it I also showed no quit
  • Related