這似乎是一個非常容易回答的問題,但我只是一個需要快速幫助的初學者。PyGame - 繪製一個像素並打印出它的座標
我試圖創建一個程序,當你在pyGame窗口上點擊某個地方時,它會打印出你用鼠標左鍵點擊它,並打印出它在哪裏的座標按下。我已經有了。我在繪製pyGame窗口中的像素時遇到了問題。基本上,我希望它繪製一個像素,我按下了pyGame窗口。
#!/usr/bin/env python
#import the module for use
import pygame
#setting up some variables
running = 1
LEFT = 1
#Set up the graphics area/screen
screen=pygame.display.set_mode((640,400))
#continuous loop to keep the graphics running
while running==1:
event=pygame.event.poll()
if event.type==pygame.QUIT:
running=0
pygame.quit()
elif event.type==pygame.MOUSEBUTTONDOWN and event.button==LEFT:
print "You pressed the left mouse button at (%d,%d)" %event.pos
elif event.type==pygame.MOUSEBUTTONUP and event.button==LEFT:
print "You released the left mouse button at (%d,%d)" %event.pos
如果你能幫忙,我該怎麼做? – user1861480
@ user1861480 - 進行了更改,它應更改您單擊的每個像素的顏色並將其拖到紅色。 – Aesthete
我很抱歉。我是這個初學者。我想知道,我在代碼中的哪個位置放置了這個?因爲我希望它能像當我點擊pyGame窗口上的任何地方時,就會出現一個新的像素。當我把這段代碼放入時,它告訴我x沒有屬性 – user1861480