Hi, i decided to create simple program that changes your computer brightness based on time you inputed(in my first steps for testing it i’m working with seconds). I made it, and now i want to give it gui for future using, so i used ttkbootstrap from tkinter
The problem is i want program to check each second, but it works only without GUI, when the window of input is working, my while loop doesn’t work(so program can’t check each second). Do you know what’s the thing or can i achieve it in much better way? Here’s my code:
from ensurepip import bootstrap
from struct import pack
from turtle import left
from screen_brightness_control import get_brightness, set_brightness, fade_brightness
from time import sleep, strftime
from tkinter import *
from ttkbootstrap.constants import *
import ttkbootstrap as tb #LIBRARIES
working = False
firstSecond = int()
firstChange = int()
secondSecond = int()
secondChange = int() #VARIABLES
root = tb.Window(themename="superhero")
root.title("TITLE")
root.geometry("800x500")
def program(): #THE WHOLE PROGRAM
currentSecond = int(strftime("%S"))
print(currentSecond)
if currentSecond >= firstSecond and currentSecond < secondSecond:
set_brightness(firstChange)
elif currentSecond >= secondSecond or currentSecond < firstSecond:
set_brightness(secondChange)
def save(): #IF USER PRESSES BUTTON, IT SAVES VARIABLES
try:
global firstSecond
firstSecond = int(fsEntry.get())
global secondSecond
secondSecond = int(ssEntry.get())
global firstChange
firstChange = int(ffEntry.get())
global secondChange
secondChange = int(sfEntry.get())
global working = True
except:
print("LOL ERROR")
while working == True:
program()
sleep(1)
myLabel = tb.Label(text="Brightness Program", font=("Berlin Sans FB", 35), bootstyle="default")
myLabel.pack(pady=10)
#LABELS AND ENTRIES
fsLabel = tb.Label(text="First time", font=("Berlin Sans FB", 10), bootstyle="default")
fsLabel.pack()
fsEntry = tb.Entry(root, bootstyle="info", font=("Berlin Sans FB", 10), foreground="light blue", width=4)
fsEntry.pack(pady=5)
ffLabel = tb.Label(text="First force", font=("Berlin Sans FB", 10), bootstyle="default")
ffLabel.pack()
ffEntry = tb.Entry(root, bootstyle="info", font=("Berlin Sans FB", 10), foreground="light blue", width=3)
ffEntry.pack(pady=5)
myLabel2 = tb.Label(text="|", font=("Berlin Sans FB", 10), bootstyle="default")
myLabel2.pack(padx=5)
ssLabel = tb.Label(text="Second time", font=("Berlin Sans FB", 10), bootstyle="default")
ssLabel.pack()
ssEntry = tb.Entry(root, bootstyle="info", font=("Berlin Sans FB", 10), foreground="light blue", width=4)
ssEntry.pack(pady=5)
sfLabel = tb.Label(text="Second force", font=("Berlin Sans FB", 10), bootstyle="default")
sfLabel.pack()
sfEntry = tb.Entry(root, bootstyle="info", font=("Berlin Sans FB", 10), foreground="light blue", width=3)
sfEntry.pack(pady=5)
myButton = tb.Button(text="SAVE", bootstyle="primary, outline", command=save)
myButton.pack(pady=30)
root.mainloop()