【发布时间】:2022-06-14 04:21:19
【问题描述】:
我正在尝试使用Guizero 在 python 3 中制作幻灯片。我似乎无法使下一个和后退按钮与时间重置一起使用。
from guizero import *
app = App(bg='#121212',title='Guizero - slide show',width=500,height=500)
#list of images
images = ["img1.jpg", "img2.png", "img3.jpg", "img4.jpg"]
#sets what slide to start with
current_slide=0
#changes current slide displayed
def slideShow():
global current_slide
if len(images)-1>current_slide:
current_slide+=1
picture.image=images[current_slide]
else:
current_slide=0
picture.image=images[current_slide]
#Function runs to change slide on button push
def slide_change(Change):
global current_slide
current_slide+=Change
picture.image=images[current_slide]
#starter image
picture = Picture(app, image=images[0])
#set picture size
picture.width=app.width-100
picture.height=app.height-100
#Time based loop
picture.repeat(2000, slideShow)
#Buttons to change slides
Back_button = PushButton(app, text='Back',command = lambda:slide_change(-1))
Back_button.text_color='white'
Next_button = PushButton(app, text='Next',command = lambda:slide_change(1))
Next_button.text_color='white'
app.display()
我要做什么
- 按下按钮时在幻灯片之间移动
- 幻灯片更换后的重置时间(每张幻灯片 2 秒)
我正在使用什么
- Python 3.7.9
- Guizero 1.3.0
【问题讨论】:
标签: python-3.x loops tkinter slideshow guizero