



我想用pygame寫幾個2d小游戲熟悉一下python語法,就用pycharm安裝了pygame1.9.3,當時用的是pythong3.6.1 64位的 結果pygame包是安裝成功了但是參考的時候就出現了圖上的警告 發現pygame包里面的類和一些方法不能用
1.pygame雖然安裝成功了,但是里面的 pygame.init()出現如下警告:
Cannot find reference 'init' in '__init__.py' less... (Ctrl+F1)
This inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Top-level and class-level items are supported better than instance items.
2.在用pygame.draw.lines(surface, color,closed,pointlist,width)時也報錯:
Traceback (most recent call last):
File "G:/Python/新建檔案夾/....py", line 17, in <module>
pygame.draw.lines(DISPLAYSURF, BLUE, (60, 60), (120, 60), 4)
TypeError: points must be number pairs
3.用QUIT的時候也報錯了
Unresolved reference 'QUIT' less... (Ctrl+F1)
This inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Top-level and class-level items are supported better than instance items.
4.第一次裝pygame時 我還裝了Livewires包(繼承pygame的一個簡版pygame包)也是安裝成功有些方法不能參考
我百度了好多網站 在各個論壇看了很多帖子總結了以下可能出現的問題
1.pygame和python版本不匹配
于是我就下載了python3.6.5 32位的 然后配置pycharm的解釋器成32位的python,再用安裝pycharm安裝pygame。問題依然沒有解決
2.可能是pycharm的問題
于是我升級了一下pycharm 從2017.3升級到2018.1 然后用pycharm安裝了matlotlib包 這個包使用沒有問題能繪制出折線圖
3.python版本問題
我就又升級了一下python到3.6.5 64位 再配置pycharm安裝pygame 問題依然存在
4.pycharm的Project Structure設定問題
我把使用的site-packages檔案夾設定成 Sources 問題依然沒有解決
下面是那段代碼
import pygame,sys
from pygame.locals import *
pygame.init()
DISPLAYSURF = pygame.display.set_mode((500, 400), 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.fill(WHITE)
pygame.draw.polygon(DISPLAYSURF, GREEN, ((146, 0), (291, 106), (236, 277), (56, 277), (0, 106)))
#pygame.draw.lines(DISPLAYSURF, BLUE, (60, 60), (120, 60), 4)
#pygame.draw.lines(DISPLAYSURF, BLUE, (120, 60), (60, 120))
#pygame.draw.lines(DISPLAYSURF, BLUE, (60, 120), (120, 120), 4)
pygame.draw.circle(DISPLAYSURF, BLUE, (300, 50), 20, 0)
pygame.draw.ellipse(DISPLAYSURF, RED, (300, 250, 40, 80), 1)
pygame.draw.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
# run the game loop
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
如果把pygame.draw.lines()那幾行注釋掉的話 程式能運行也能正常關閉(但是QUIT和pygame.quit()明明報錯了啊,應該不能正常關閉的啊)
從發現問題到現在前前后后弄了一個星期,也沒有解決掉問題
真的讓人抓狂啊 uj5u.com熱心網友回復:
pygame.draw.lines(DISPLAYSURF, BLUE, True, ((120, 60),(60, 60)), 4)pygame.draw.lines(DISPLAYSURF, BLUE, True,((120, 60), (60, 120)),4)
pygame.draw.lines(DISPLAYSURF, BLUE, True,((60, 120), (120, 120)), 4)
這里的兩個點是要用元組來包裹的
uj5u.com熱心網友回復:
pygame.draw.lines原型:pygame.draw.lines(Surface, color, closed, pointlist, width=1): return Rect
用途:用于繪制一系列直線段。closed是一個布爾變數,如果closed為真,那么表示需要把第一點和最后一點連接起來。這些點來自pointlist,一個包含坐標點的串列。這個函式不會繪制線條的端點,也沒有斜角連接(miter joints),而且角度小和線條粗的連線看起來會有點奇怪( Lines with sharp corners and wide line widths can have improper looking corners.)。
uj5u.com熱心網友回復:
uj5u.com熱心網友回復:
哦哦,看來我把draw.lines()和draw.line弄混淆了
uj5u.com熱心網友回復:
對的,我也能運行出來這個圖
但是pycharm會報錯。。。。
uj5u.com熱心網友回復:
解決了嗎 我的也是顯示沒有quit轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/31631.html
上一篇:【求助】python編程:從入門到實踐 專案3Web應用程式 出現TypeError at /topics/1/ 問題,江湖救急啊
下一篇:大神救急!!!!!!!!!
