首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Guizero/tkinter中制作幻灯片?

如何在Guizero/tkinter中制作幻灯片?
EN

Stack Overflow用户
提问于 2022-06-08 20:02:49
回答 1查看 62关注 0票数 0

我正试图用吉泽罗在python 3中制作幻灯片。我似乎无法使下一个按钮和后退按钮与时间重置工作。

代码语言:javascript
复制
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()

我想做什么,

  1. 按下按钮在幻灯片之间移动
  2. 幻灯片更改后的重置时间(每张幻灯片2秒)

我用的是

  1. Python 3.7.9
  2. Guizero 1.3.0
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-13 20:21:19

代码语言:javascript
复制
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
time_per_slide=2000

#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 nextImage():
    global current_slide
    if current_slide < len(images)-1: 
            current_slide+=1     
    else: 
        current_slide=0
    picture.image=images[current_slide]
    app.cancel(slideShow)
    #Restarts slide show
    picture.repeat(time_per_slide, slideShow)
    

def previousImage():
    global current_slide
    if current_slide > 0:
      current_slide-=1      
    
    else:
        current_slide=len(images)-1    
    picture.image=images[current_slide]
    app.cancel(slideShow)
    #Restarts slide show
    picture.repeat(time_per_slide, slideShow)
    
    
#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(time_per_slide, slideShow)


#Buttons to change slides 
Back_button = PushButton(app, text='Back', command =previousImage)
Back_button.text_color='white'


Next_button = PushButton(app, text='Next',command =nextImage)
Next_button.text_color='white'

app.when_closed=quit
app.display()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72551570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档