I am using pygame to load an image (Count.png, just a grey background png file) as an overlay counter to anything that is currently displayed onscreen. During this process if I let this run for 5 minutes all the sudden the image quits loading (doesn't show up at the coordinates 300x300) but the program keeps running, meaning the action that is tied to the counter keeps going. In this case simple key press of e. How do I properly "close" the image so it can be reopened or prevent the image from disappearing (not really sure what happens to the image, it shows on the taskbar and action still runs every x seconds)?
What you will see is the counter just counting down on whatever image that is saved as Count.png. This runs from a simple tkinter button. The button starts an automation process and starts this counter. When the counter reaches 0, the process is restarted which should include the counter. I wrote out all the parts except the tkinter window with a button. The icon.ico file is exactly what it states so instead of the nice little feather on the taskbar I get the actual icon tied to the application.
import os
from ctypes import windll
import pygame
import time
import pyautogui
def countingRoutine():
locx = 300
locy = 300
os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (locx, locy)
pygame.init()
set_window_pos = windll.user32.SetWindowPos
screen = pygame.display.set_mode((50, 30), pygame.NOFRAME)
set_window_pos(pygame.display.get_wm_info()['window'], -1, locx, locy, 0, 0,
0x0001)
clock = pygame.time.Clock()
counter, text = 13, '00'.ljust(4)
pygame.time.set_timer(pygame.USEREVENT, 1000)
font = pygame.font.SysFont('Avatar', 23)
while True:
for e in pygame.event.get():
if e.type == pygame.USEREVENT:
if counter > 0:
counter -= 1
text = str(counter).center(0).rjust(4)
else:
main()
screen.fill((255, 191, 0))
for_trans = pygame.image.load_extended('Count.png')
loadImg = pygame.image.load_basic('icon.ico')
pygame.display.set_icon(loadImg)
screen.blit(for_trans, (0, -15))
screen.blit(font.render(text, True, (200, 0, 200)), (0, 0))
pygame.display.flip()
clock.tick(counter)
continue
def msgBox():
pyautogui.confirm("Enabling Automated process\n ", "Activating", buttons=
['Affirmative'])
def main():
while True:
pyautogui.hotkey('e')
countingRoutine()
time.sleep(13)
if __name__ == "__main__":
msgBox()
main()