title: How to change the desktop background according to the time with python?
body: <p>So I have this code which changes the background according to the local time. The problem is that once the code is run it stops, but I want it to keep checking forever until the time has changed. So is there a way to add like a while loop or any kind of for loop. Also, how would you add this python file to a task in windows so it runs forever?</p>
  
  <p>The code:</p>
  
  <pre><code>import ctypes
  import time
  
  dawn_wallpaper = "C:/Users/meena/Downloads/Backgrounds/Mac_Dawn.jpg"
  sunrise_wallpaper = "C:/Users/meena/Downloads/Backgrounds/Mac_Sunrise.jpg"
  mid_day_wallpaper = "C:/Users/meena/Downloads/Backgrounds/Mac_MidDay.jpg"
  dusk_wallpaper = "C:/Users/meena/Downloads/Backgrounds/Mac_Dusk.jpg"
  night_wallpaper = "C:/Users/meena/Downloads/Backgrounds/Mac_Night.jpg"
  midnight_wallpaper = "C:/Users/meena/Downloads/Backgrounds/Mac_Midnight.jpg"
  
  result = time.localtime()
  hours = result.tm_hour
  
  if 3 &lt;= hours &lt;= 5:
     user32 = ctypes.WinDLL('user32', use_last_error=True).SystemParametersInfoW(20, 0, dawn_wallpaper, 0)
  elif 6 &lt;= hours &lt;= 11:
     ctypes.windll.user32.SystemParametersInfoW(20, 0, sunrise_wallpaper, 0)
  elif 12 &lt;= hours &lt;= 17:
     ctypes.windll.user32.SystemParametersInfoW(20, 0, mid_day_wallpaper, 0)
  elif 18 &lt;= hours &lt;= 20:
     ctypes.windll.user32.SystemParametersInfoW(20, 0, dusk_wallpaper, 0)
  elif 21 &lt;= hours &lt;= 22:
     ctypes.windll.user32.SystemParametersInfoW(20, 0, night_wallpaper, 0)
  elif 23 &lt;= hours &lt;= 2:
     ctypes.windll.user32.SystemParametersInfoW(20, 0, midnight_wallpaper, 0)
  </code></pre>