Hello,
I started Python a few weeks ago and have already made some little programs like: Cable sag calculation with matplotlib and auto take screenshot on several websites with selenium and webdriver chrome.
But with the following thing I get not the result that I want after days of googling and searching on github:
A very simple slideshow!
Attempt 1:
Does everything except it makes my slideshow random. I want an fixed order of showing the images.
Has an fixed order of showing the images but I don't can apply the allignment of my images.
Playing with while loops, .... but I can only print 1 image. I thought if I can make the image variabel by saying A = img1 and after 5 seconds (time.sleep(5)) A = img2, but img = pyglet.image.load(a) always takes the last option (img2)
Any help?
I started Python a few weeks ago and have already made some little programs like: Cable sag calculation with matplotlib and auto take screenshot on several websites with selenium and webdriver chrome.
But with the following thing I get not the result that I want after days of googling and searching on github:
A very simple slideshow!
Attempt 1:
Does everything except it makes my slideshow random. I want an fixed order of showing the images.
import argparse import random import os import pyglet import time def update_image(dt): image_paths = get_image_paths(args.dir) img = pyglet.image.load(random.choice(image_paths)) sprite.image = img sprite.x = ((1920 - (int(img.width)))/2) sprite.y = ((1080 - (int(img.height)))/2) window.clear() def get_image_paths(input_dir='.'): paths = [] for root, dirs, files in os.walk(input_dir, topdown=True): for file in sorted(files): if file.endswith(('jpg', 'png', 'gif', 'JPG')): path = os.path.abspath(os.path.join(root, file)) paths.append(path) return paths window = pyglet.window.Window(fullscreen=True) @window.event def on_draw(): sprite.draw() if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('dir', help='directory of images', nargs='?', default=os.getcwd()) args = parser.parse_args() image_paths = get_image_paths(args.dir) img = pyglet.image.load(random.choice(image_paths)) sprite = pyglet.sprite.Sprite(img) pyglet.clock.schedule_interval(update_image, 6.0) pyglet.app.run()Attempt 2:
Has an fixed order of showing the images but I don't can apply the allignment of my images.
import pyglet # Create and open a window window = pyglet.window.Window(fullscreen=True) # Load sprites s0 = pyglet.image.load('Windfinder.jpg') s1 = pyglet.image.load('Meteovista.jpg') s2 = pyglet.image.load('Vorderingsstaat.jpg') sprites = [s0, s1, s2] # Animation anim = pyglet.image.Animation.from_image_sequence(sprites, 3, True) sprite = pyglet.sprite.Sprite(anim) #sprite.image = anim #sprite.x = ((1920 - (int(anim.width))) / 2) #sprite.y = ((1080 - (int(anim.height))) / 2) @window.event def on_draw(): window.clear() sprite.draw() if __name__ == '__main__': pyglet.app.run()Attempt 3:
Playing with while loops, .... but I can only print 1 image. I thought if I can make the image variabel by saying A = img1 and after 5 seconds (time.sleep(5)) A = img2, but img = pyglet.image.load(a) always takes the last option (img2)
import argparse import random import os import pyglet import time a = str('Windfinder.jpg') window = pyglet.window.Window(fullscreen=True) @window.event def on_draw(): sprite.draw() img = pyglet.image.load(a) sprite = pyglet.sprite.Sprite(img) sprite.x = ((1920 - (int(img.width)))/2) sprite.y = ((1080 - (int(img.height)))/2) pyglet.app.run()Al my searching on Github shows a lot of slideshows with a lot of code. I think I don't need such much code and I just want it to be simple.
Any help?