I'm building a boggle game, and I want to add a circle countdown timer to the game. I built a timer using pygame, and the whole game is built on tkinter. Is it possible to merge the two windows so that the timer appears on the game board when the background of the game board is the background of the timer. And that the timer will run along with the game.
This is my timer code- in pygame:
import pygame
import tkinter as tk
class Timer:
def __init__(self):
pygame.init()
self.window = pygame.display.set_mode((200, 200))
self.clock = pygame.time.Clock()
self.font = pygame.font.SysFont(None, 30)
self.sec = 59
self.counter = 3
self.text = self.font.render(str(self.sec), True, (0, 128, 0))
timer_event = pygame.USEREVENT + 1
pygame.time.set_timer(timer_event, 600)
def drawArc(surf, color, center, radius, width, end_angle):
arc_rect = pygame.Rect(0, 0, radius * 2, radius * 2)
arc_rect.center = center
pygame.draw.arc(surf, color, arc_rect, 0, end_angle, width)
run = True
while run:
self.clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
elif event.type == timer_event:
if 0 < self.sec < 60:
self.sec -= 1
else:
self.counter -= 1
self.sec = 59
self.text = self.font.render(str(self.counter) + ":" + str(self.sec), True, (113, 113, 198))
if self.sec == 0 and self.counter == 0:
pygame.time.set_timer(timer_event, 0)
self.window.fill((255, 255, 255))
text_rect = self.text.get_rect(center=self.window.get_rect().center)
self.window.blit(self.text, text_rect)
drawArc(self.window, (171, 130, 255), (100, 100), 50, 10, 2 * math.pi * self.sec / 60)
pygame.display.flip()
This is my main tkinter code-
import tkinter as tk
from PIL import ImageTk
GAME_IMAGE = "game_screen.png"
root = tk.Tk()
canvas = tk.Canvas(root, width=700,
height=500, bd=0, highlightthickness=0)
canvas.pack()
tk_img = ImageTk.PhotoImage(file=GAME_IMAGE)
canvas.create_image(400, 270,
image=tk_img)
root.mainloop()