У меня есть доказательство концепции Python, где он просто перерисовывает окно, отслеживает время и удаляет изображения по истечении времени. Кажется, это нормально, но кажется неуклюжим, не уверен, что доверяю этому запуску, если бы было 1000 изображений. Пример приведен ниже.
Независимо от того, есть ли лучший способ сделать это на другом языке? Если да, то есть ли у кого-нибудь пример?
import pygame
import win32api
import win32con
import win32gui
import time
import random
class testHug():
def __init__(self):
pygame.init()
self.screen_width = 800
self.screen_height = 600
self.screen = pygame.display.set_mode((self.screen_width, self.screen_height))
self.hwnd = pygame.display.get_wm_info()["window"]
win32gui.SetWindowLong(self.hwnd, win32con.GWL_EXSTYLE, win32gui.GetWindowLong(
self.hwnd, win32con.GWL_EXSTYLE) | win32con.WS_EX_LAYERED)
win32gui.SetLayeredWindowAttributes(self.hwnd, win32api.RGB(255, 0, 128), 0, win32con.LWA_COLORKEY)
self.screen.fill((255, 0, 128))
pygame.display.flip()
self.image_list = [
pygame.image.load("image.png"),
pygame.image.load("image2.png"),
pygame.image.load("image3.png")
]
self.duration = 4000
self.killtime = 10000
self.current_ticker_time = pygame.time.get_ticks()
self.image_dict = {'user1' : {'image': pygame.image.load("image.png"), 'shown':0, 'starttime': self.current_ticker_time, 'widthmodifier': random.randrange(-350,350), 'heightmodifier': random.randrange(-250,250)} }
self.current_ticker_time = pygame.time.get_ticks()
self.image_dict['user2'] = {'image': pygame.image.load("image2.png"), 'shown':0, 'starttime': self.current_ticker_time, 'widthmodifier': random.randrange(-350,350), 'heightmodifier': random.randrange(-250,250)}
self.current_ticker_time = pygame.time.get_ticks()
self.image_dict['user3'] = {'image': pygame.image.load("image3.png"), 'shown':0, 'starttime': self.current_ticker_time, 'widthmodifier': random.randrange(-350,350), 'heightmodifier': random.randrange(-250,250)}
self.current_ticker_time = pygame.time.get_ticks()
self.image_dict['user4'] = {'image': pygame.image.load("image4.png"), 'shown':0, 'starttime': self.current_ticker_time, 'widthmodifier': random.randrange(-350,350), 'heightmodifier': random.randrange(-250,250)}
self.running = True
def processImages(self, user, image):
self.current_ticker_time = pygame.time.get_ticks()
self.image_dict[user] = {'image': pygame.image.load(image), 'shown':0, 'starttime': self.current_ticker_time, 'widthmodifier': random.randrange(-350,350), 'heightmodifier': random.randrange(-250,250)}
self.image_index = 0
while self.running:
elapsed_time = pygame.time.get_ticks() - self.current_ticker_time
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.running = False
if elapsed_time >= self.killtime and self.image_index >= len(self.image_dict):
break
if elapsed_time >= self.duration and self.image_index < len(self.image_dict):
self.image_index += 1
self.screen.fill((255, 0, 128))
pygame.display.flip()
for x in range(0, self.image_index):
if (self.image_index
Подробнее здесь: https://stackoverflow.com/questions/791 ... -new-image
Динамически добавлять изображения с собственным таймером в окно при передаче нового изображения? ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Оператор Socketio.emit не обновляет браузер при вызове из функции, управляемой таймером
Anonymous » » в форуме Python - 0 Ответы
- 11 Просмотры
-
Последнее сообщение Anonymous
-