I created a page for playing videos, there is a button to play videos, and there is a button to switch the screen, There is also a video playback button on the second page, But the problem is if the play key of the second page is empty (I will trigger the event annotation), The program can be executed and the screen switches smoothly But once there's something in there he will show undefined
import sys,random,math,pygame
import time
from pygame.locals import *
from moviepy.editor import *
def button(screen, position, text, size, colors="white on blue"):
fg, bg = colors.split(" on ")
font = pygame.font.SysFont("Arial", size)
text_render = font.render(text, 1, fg)
x, y, w , h = text_render.get_rect()
x, y = position
pygame.draw.line(screen, (150, 150, 150), (x, y), (x + w , y), 5)
pygame.draw.line(screen, (150, 150, 150), (x, y - 2), (x, y + h), 5)
pygame.draw.line(screen, (50, 50, 50), (x, y + h), (x + w , y + h), 5)
pygame.draw.line(screen, (50, 50, 50), (x + w , y+h), [x + w , y], 5)
pygame.draw.rect(screen, bg, (x, y, w , h))
# print(screen.blit(text_render, (x, y)))
return screen.blit(text_render, (x, y))
pygame.init()
window = pygame.display.set_mode((1400,700))
pygame.display.set_caption('影片播放測試')
font = pygame.font.Font('aa.ttf',50)
window.fill((120,120,120))
pygame.display.flip()
sys_start = False
sys2 =False
b1 = button(window, (650, 400), "game start", 50, "white on green")
b2 = button(window, (650, 500), "game off", 50, "red on yellow")
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.QUIT
pygame.display.update()
if event.type == pygame.MOUSEBUTTONDOWN:
if b2.collidepoint(pygame.mouse.get_pos()):
pygame.quit()
# 開始
elif b1.collidepoint(pygame.mouse.get_pos()):
sys_start = True
elif b3.collidepoint(pygame.mouse.get_pos()):
# videomode = pygame.display.set_mode((1400,700))
pygame.display.set_caption('Hello World!')
print("即將撥放影片")
clip = VideoFileClip('1-1test.mp4')
clip.preview()
#the problem is here
elif b5.collidepoint(pygame.mouse.get_pos()):
pygame.display.set_caption('Hello World!')
print("即將撥放影片")
clip = VideoFileClip('1-1test.mp4')
clip.preview()
elif b22.collidepoint(pygame.mouse.get_pos()):
sys_start = False
sys2 = True
elif b27.collidepoint(pygame.mouse.get_pos()):
sys2 = False
sys_start = True
if sys_start == True:
# print('影片播放')
window.fill((120,120,120))
b3 = button(window, (390, 400), "playvideo", 50, "white on green")
b22 = button(window, (1350, 350), ">", 50, "white on red")
pygame.display.update()
if sys2 == True:
# print('影片播放')
window.fill((120,120,120))
b5 = button(window, (390, 400), "playvideo2", 50, "white on green")
b27 = button(window, (0, 350), "<", 50, "white on red")
pygame.display.update()
I marked the problematic part, Hope you guys can help me
Aucun commentaire:
Enregistrer un commentaire