1 year ago

#341559

test-img

alpha6678

how to convert a str key= to an integer?

I'm having difficulty converting a key into an integer numeral, or finding a better way for Input to capture directly into a numeral so I don't need to convert

I tried converting as follows tempo_init = int(tempo) but the result is still a string, while what i expected was an integer numeral, so i add it to the schedule and it runs the code every certain amount of minutes.

If I leave out the graphical interface of PySimpleGUI, the code runs normally the way I expect.

import os

import sys

import time

import schedule

import PySimpleGUI as sg

import pyautogui


sg.theme('DarkAmber')

layout = [[sg.Text('De quanto em quantos minutos rodar o anuncio?')], 
          [sg.InputText(key='tempo')],
          [sg.Button('OK'), sg.Button('Cancel')]]


def start_python_code():
    pyautogui.press('playpause')
    pyautogui.PAUSE = 1.0
    from pygame import mixer
    mixer.init()
    mixer.music.load('C:\\Sounds\\adsSound.mp3')
    mixer.music.play()
    while mixer.music.get_busy():
        pass
    pyautogui.press('playpause')


def temp_interval():
    schedule.every(adsTimeInterval).minutes.do(start_python_code)


def temp_read():
    while 1:
        schedule.run_pending()
        time.sleep(1)



window = sg.Window('Sound Ads', layout)

while True:
    event, values = window.read()
    tempo = sg.InputText(key='tempo')
    tempo_init = int(tempo)
    adsTimeInterval = tempo_init
    if event == sg.WIN_CLOSED or event == 'Cancel':
        break
    
    start_python_code()
    temp_interval()
    temp_read()

python

python-3.x

schedule

pyautogui

pysimplegui

0 Answers

Your Answer

Accepted video resources