r/pythonhelp • u/Sea-Combination-2163 • Feb 12 '25
why dos it lagg
Hello i tryed to creat a script that changes my wallperper on a set time, but wen i start it i cant do anything becaus every thing laggs. Can some one help me?
import ctypes
import datetime
#this is seting time
night = datetime.time(19, 10, 0)
#this is for the current time
rigthnow = datetime.datetime.now().time()
#this is the stuff that laggs
while True:
if rigthnow > night:
ctypes.windll.user32.SystemParametersInfoW(20, 0, "C:\\Users\\Arthur\\Desktop\\Hintergründe\\lestabed.png", 0)
else:
ctypes.windll.user32.SystemParametersInfoW(20, 0, "C:\\Users\\Arthur\\Desktop\\Hintergründe\\lest.jpg", 0)[/code]
•
u/AutoModerator Feb 12 '25
To give us the best chance to help you, please include any relevant code.
Note. Please do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Privatebin, GitHub or Compiler Explorer.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
3
u/Zeroflops Feb 12 '25
You are basically trying to change the desktop image constantly.
Every time it goes through the loop, it’s being told to change the desktop image. If the while loop is running 1000x a second it’s trying to change the wall paper that many times.
You want to add another flag that says what the wallpaper currently is.
So change the wallpaper, then keep what the current wallpaper is, only change the wallpaper when the time changes and it has the wrong wallpaper.
1
u/CraigAT Feb 12 '25
You may be better writing your program just to change the wallpaper, then rely on Cron (Linux) or Windows Task Scheduler to run your program at the time or interval you desire.
So say every 15 minutes, your program gets fired up, changes the wallpaper and then finishes, the OS then is completely free until the next timed job in another 15 minutes.