0

Windows10/Python3

So i have the beep.pyw file located in startup:shell, it beeps every 30 minutes automatically when you open the pc.

And i'm using Tkinter to make a GUI widget "widget.py" which contains 4 advices to do in the breaks like (breathing stretching, hydrating etc...) = Done

Problem is :

How to open the widget every time the pc beeps. Should i put both files in one file or how can i add the statement to open the "widget.py" in the "beep.pyw" ?

This is the beep.pyw :

import time
import winsound

beep_time = 30*60
def beep_every60():
    
    while True :

        winsound.Beep(2000, 1000)
        winsound.Beep(2000, 1000)
        time.sleep(beep_time)

beep_every60()

1 Answers1

1
import time
import winsound
from tkinter import *



class WindowsBeep(Tk):
    def __init__(self):
        super().__init__()

        self.title_ = "Windows Beep"
        self.title(self.title_)

        self.bg = "#222222"
        self.fg = "#cccccc"
        self["bg"] = self.bg

        self.__largura_tela__ = self.winfo_screenwidth()
        self.__altura_tela__ = self.winfo_screenheight()

        self.porcentagem_largura = 0.50
        self.porcentagem_altura = 0.75

        self.__largura_app__ = int(self.__largura_tela__ * self.porcentagem_largura)
        self.__altura_app__ = int(self.__altura_tela__ * self.porcentagem_altura)

        self.centro_l_janela = int((self.__largura_tela__ // 2) - (self.__largura_app__ // 2) + 2)
        self.centro_a_janela = int((self.__altura_tela__ * (1 - self.porcentagem_altura)) // 2)

        self.__center__ = f"{self.__largura_app__}x{self.__altura_app__}+{self.centro_l_janela}+{self.centro_a_janela}"

        self.geometry(self.__center__)





beep_time = 30*60
def beep_every60():
    while True :
        winsound.Beep(2000, 1000)
        winsound.Beep(2000, 1000)
        WindowsBeep().mainloop()
        time.sleep(beep_time)

beep_every60()
  • Its bad practise to use wildcard imports and double underscores. – Thingamabobs Nov 17 '21 at 21:04
  • If you think bad, do better and teach me. – Cristielson Silva Nov 17 '21 at 21:36
  • Wildcard imports can lead to name conflicts, especially for beginners that can be confusing. Double underscores are syntax for privacy and can also lead to unintended consequences. – Thingamabobs Nov 17 '21 at 21:52
  • #Button self.button = ttk.Button(self, text='Got it!') self.button['command'] = self.button_clicked self.button.pack() def button_clicked(self): HealthReminder().destroy() #try destroy(self) Adding a button this way works ? – Marinos TBH Nov 28 '21 at 18:42