简体   繁体   English

GIF PySimpleGui?

[英]Gifs PySimpleGui?

is it possible to put a GIF or a video in a window using PySimpleGui?是否可以使用 PySimpleGui 将 GIF 或视频放入 window 中? I have a code where it shows an image in the first window, where I would like to put an animated gif, I tried some ways but it didn't work.我有一个代码,它在第一个 window 中显示图像,我想在其中放置一个动画 gif,我尝试了一些方法,但没有成功。

[sg.Image(filename='2.png')], #window where I would like to show the gif [sg.Image(filename='2.png')], #window 我想在哪里显示 gif

from asyncore import write
import PySimpleGUI as sg
import pyautogui 
import time 
import os 
t = time.sleep
gui = pyautogui


os.system('cls') # limpa o terminal
users = ['GUILHERME','GABRIEL','MATHEUS','RAUL','SATO','MAURICE']
workers = ['WORKER01','WORKER02','WORKER03','WORKER04']
sg.theme('DarkAmber')
global values
global hand 

hand= sg.InputText(key ='hand',do_not_clear = True, size =(20,1))
canal = sg.InputText(key ="canal", size =(20,1))
sleep1 = sg.InputText(key ="sleep1", size =(20,1))
sleep2 = sg.InputText(key ="sleep2", size =(20,1))
par = sg.InputText(key ="par", size =(20,1))
perc = sg.InputText(key ="perc", size =(20,1))
usu = sg.Listbox(users, key = 'usu',size = (20,1))
worker = sg.Listbox(workers, key = 'worker', select_mode="",size = (20,1))

layout1 = [

    [sg.Image(filename='2.png')],  #window where I would like to show the gif
    [sg.Text('Bem Vindo Usário, siga o questionamento para identificar seus dados:', size = (50,1))],
    [sg.Text("VALOR DA MÃO?" ,size = (25,1)),hand],
    [sg.Text("CANAL DE TRABALHO?", size = (25,1)),canal],
    [sg.Text("FREQUÊNCIA LATERAL? " ,size = (25,1)),sleep1],
    [sg.Text("FREQUÊNCIA VERTICAL?" ,size = (25,1)),sleep2],
    [sg.Text("QUAL PAR VOCÊ QUER?" ,size = (25,1)),par],
    [sg.Text("QUAL RANGE VOCÊ QUER?" ,size = (25,1)),perc],
    [sg.Text("QUAL PERFIL?",size =(25,1)),usu],  # SELECT MODE = MULTIPLE PARA SELECIONAR MAIS DE UMA OPÇÃO AO MESMO TEMPO 
    [sg.Text("QUAL WORKER?",size =(25,1)),worker], 
    [sg.Text("QUAL PRAZO?",size =(24,1)),sg.Radio("LONGO","prazo",True,key="longoprazo"),sg.Radio("CURTO","prazo",key="curtoprazo")], # sg.radio são definidas como True or False, então crie uma função 
    [sg.Text("QUAL LADO?",size =(24,1)),sg.Radio("DOWN","lado",True,key="ladodown"),sg.Radio("UP","lado",key="ladoup")],
    [sg.Button("Entrar"), sg.Button("Cancelar")],
    ]

def tratar_lado(): 
    if values['ladodown'] == True: 
        gui.write('DOWN')
    else: 
        gui.write('UP')

def tratar_prazo(): 
    if values['longoprazo'] == True: 
        gui.write('LONGO')
    else: 
        gui.write('CURTO')

def abrir_putty1():
    gui.press('Win');t(0.5);
    gui.write('PUTTY');t(0.5);gui.press('Return');t(1);gui.write('temporario');t(1);gui.press('Return');t(3) #gui.write(values['usu'][0])
    gui.write('batata123');gui.press('Return')    
    
def iniciar():
    gui.press('capslock')
    gui.press('Win');t(0.5); 
    gui.write('PUTTY');t(0.5);gui.press('Return');t(1);gui.write("####");t(1);gui.press('Return');t(2) #gui.write(values['usu'][0])
    gui.write('####');gui.press('Return');
    gui.write('cd');gui.press('tab');gui.write(values['worker'][0]);gui.press('tab');tratar_lado();gui.press('Return');print('A pasta local foi localizada com sucesso...');window.refresh()
    gui.write('nano coloca.tty',interval = 0.3);gui.press('Return');print('Preparando para editar o Putty');window.refresh()
    gui.hotkey('Ctrl','W');gui.write("LIMIT", interval = 0.3);(1);gui.press('Return');t(0.3) #pesquisa LIMIT no nano 
    gui.press('right', presses = 25, interval= 0.1);gui.press('Backspace', presses = 2);gui.write(values["hand"]);print('Primeira mão editada com sucesso...');window.refresh() #Edita a Primeira Mão 
    gui.hotkey('Ctrl', 'W');gui.write('limit.tty', interval = 0.1);t(0.5);gui.press('Return');gui.press('right', presses = 29, interval = 0.1);gui.press('Backspace', presses = 4, interval =0.1) # edita a segunda mão
    t(0.5);gui.write(values["hand"]);t(0.5);print('Segunda mão editada com sucesso...');window.refresh() #inputa a segunda mão e printa 

    gui.hotkey('Ctrl', 'W');t(0.5);gui.write('totordens', interval =0.1);t(0.5);pyautogui.press('Return');t(0.5);gui.press('right', presses = 33, interval= 0.2)
    t(0.5);gui.press('backspace', presses = 1, interval = 0.3);t(0.5);gui.write(values[canal]);print('Canal de trabalho editado com sucesso...');window.refresh()


def janela_acompanhamento(values2): 
    janela_layout =  [ 

            [sg.Text('DILLO BOT - INICIALIZADOR')],
            [sg.Multiline(reroute_stdout=True, size = (90,40))],
            [sg.Button('OK')]]
    janela_acompanhamento = sg.Window("Janela de Acompanhamento", janela_layout)

    while True: 
        event, values = janela_acompanhamento.read(timeout=50)
        if event in (sg.WIN_CLOSED, 'Fechar'): 
            break
        elif event == 'Entrar': 
         janela_acompanhamento.read
        elif event == 'OK':
            
            print("PROTOCOLO"+" "+"---->", end="  ");
            print("U:"+values2['usu'][0],end="  ")
            print("W:"+values2['worker'][0], end = " ")
            print("M:"+values2["hand"],end="  ")
            print("P:"+values2["par"],end="  ")
            print("R:"+values2["perc"],end="  ")
            print("C:"+values2["canal"],end="  ")
            print("S1:"+values2["sleep1"],end="  ")
            print("S2:"+values2["sleep2"],end="  ")
            
            window.refresh()    
            print('Bem vindo   '  + values2['usu'][0]+ '.      Prepare um café enquanto o Dillo Inicia!');window.refresh();iniciar()
            
            
window = sg.Window('Dillo Bot', layout1)
while True: 
    event, values = window.read()
    sg.theme('DarkAmber')
    if event in (None, "Quit"):
        break
    if event == 'Cancelar':
        break
    if event == 'Entrar': 
        window.hide()
        janela_acompanhamento(values)
window.close()

window where I would like to show the gif window 我想在哪里显示 gif

If possible, should reduce your code to only something about your question, not in full code of your project.如果可能的话,应该将您的代码减少为仅与您的问题有关的内容,而不是您项目的完整代码。

Following code demo one way to show the GIF in a window.以下代码演示了一种在 window 中显示 GIF 的方法。

import PySimpleGUI as sg

layout = [[sg.Image(sg.DEFAULT_BASE64_LOADING_GIF, key='-GIF-')]]
window = sg.Window("Title", layout)

while True:
    event, values = window.read(timeout=100)
    if event == sg.WIN_CLOSED:
        break
    elif event == sg.TIMEOUT_EVENT:
        window['-GIF-'].update_animation(sg.DEFAULT_BASE64_LOADING_GIF, time_between_frames=100)

window.close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM