尝试使用 pygame 绘制到屏幕上,无法使用任何方法
Trying to draw to the screen using pygame, cant get any method to work
这是我的代码片段,它接受文本输入并将像素绘制到屏幕上,这是命令格式
!pixel 32,32 255,255,255
##Command Format !Pixel X,Y R,G,B
def screencontrol():
##now we open the PyGame window
(width, height) = (256, 256) #more window setup
screen = pygame.display.set_mode((width, height)) #more window setup
pygame.display.flip() #more window setup
global message
#global splitmsg
while True:
commandmessage = message
pygame.init()
pygame.event.pump() ##keeps pygame window refreshed / not crash
if "!pixel" == commandmessage.lower().split(" ", 1)[0]: #Split message and check for pixel command
print("Received a draw pixel request!") #debug output
coordsforpix = commandmessage.lower().split(" ", -1)[1]
print("Extracting draw... ")
plotpixx = coordsforpix.split(",", 2)[0]
print("X = " + plotpixx)
plotpixy =coordsforpix.split(",", 2)[1]
print("Y = " + plotpixy)
plotpixrgb = commandmessage.lower().split(" ", -1)[2]
print("RGB = " + plotpixrgb)
plotpixr = plotpixrgb.split(",", 3)[0]
plotpixg =plotpixrgb.split(",", 3)[1]
plotpixb =plotpixrgb.split(",", 3)[2]
print("R G B = " + plotpixr + plotpixg + plotpixb)
print("Done extracting")
pygame.draw.circle(screen, tuple(map(int, plotpixrgb.split(",", -1))), (int(plotpixx), int(plotpixy)), 1)#plot point
commandmessage = ""
message = ""
pass
else:
pass
我已经费了 2 天时间试图让它工作,其他一切工作正常,调试输出应该是什么但它不会绘制任何像素...
提前致谢!
pygame.display.flip()
updates the full display Surface to the screen and has to be done at the end of the application loop, but pygame.init()
初始化所有导入的 pygame 模块并且只需执行一次。它必须是第一个 pygame 指令。
def screencontrol():
pygame.init() # init pygame
##now we open the PyGame window
(width, height) = (256, 256) #more window setup
screen = pygame.display.set_mode((width, height)) # create window
global message
#global splitmsg
while True:
commandmessage = message
pygame.event.pump() ##k
if "!pixel" == commandmessage.lower().split(" ", 1)[0]:
# [...]
pygame.display.flip() # update display at the end of the loop
这是我的代码片段,它接受文本输入并将像素绘制到屏幕上,这是命令格式 !pixel 32,32 255,255,255
##Command Format !Pixel X,Y R,G,B
def screencontrol():
##now we open the PyGame window
(width, height) = (256, 256) #more window setup
screen = pygame.display.set_mode((width, height)) #more window setup
pygame.display.flip() #more window setup
global message
#global splitmsg
while True:
commandmessage = message
pygame.init()
pygame.event.pump() ##keeps pygame window refreshed / not crash
if "!pixel" == commandmessage.lower().split(" ", 1)[0]: #Split message and check for pixel command
print("Received a draw pixel request!") #debug output
coordsforpix = commandmessage.lower().split(" ", -1)[1]
print("Extracting draw... ")
plotpixx = coordsforpix.split(",", 2)[0]
print("X = " + plotpixx)
plotpixy =coordsforpix.split(",", 2)[1]
print("Y = " + plotpixy)
plotpixrgb = commandmessage.lower().split(" ", -1)[2]
print("RGB = " + plotpixrgb)
plotpixr = plotpixrgb.split(",", 3)[0]
plotpixg =plotpixrgb.split(",", 3)[1]
plotpixb =plotpixrgb.split(",", 3)[2]
print("R G B = " + plotpixr + plotpixg + plotpixb)
print("Done extracting")
pygame.draw.circle(screen, tuple(map(int, plotpixrgb.split(",", -1))), (int(plotpixx), int(plotpixy)), 1)#plot point
commandmessage = ""
message = ""
pass
else:
pass
我已经费了 2 天时间试图让它工作,其他一切工作正常,调试输出应该是什么但它不会绘制任何像素... 提前致谢!
pygame.display.flip()
updates the full display Surface to the screen and has to be done at the end of the application loop, but pygame.init()
初始化所有导入的 pygame 模块并且只需执行一次。它必须是第一个 pygame 指令。
def screencontrol():
pygame.init() # init pygame
##now we open the PyGame window
(width, height) = (256, 256) #more window setup
screen = pygame.display.set_mode((width, height)) # create window
global message
#global splitmsg
while True:
commandmessage = message
pygame.event.pump() ##k
if "!pixel" == commandmessage.lower().split(" ", 1)[0]:
# [...]
pygame.display.flip() # update display at the end of the loop