Python control of desktop properties

M

Mediocre Person

Hello, all.

I'm teaching Python for the first time to some high school students, and
it's going well--Tomorrow's lesson: I'm going to show them how to use a
list comprehension to simplify a task.

One of my students is interested in using Python to control his
(Windows) desktop, and wants to write a program to change the desktop
background or wallpaper. I told him I'd look into this, but I've had to
admit defeat.

Can someone point me in the right direction, possibly post the simplest
Python program that can accomplish this. I understand this won't be
portable. At school, we use Win98SE; the student in question is using
XPHome at home, and I typically use Gentoo Linux/KDE 3.3. If there were
a single solution that would address all three environments, I'd be...
well, shocked.

Merci beaucoup,

Nick.
 
M

Mike C. Fletcher

You want to call the function:
user32.SystemParametersInfo(
SPI_SETDESKWALLPAPER,
0,
imageLocation,
|SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE
)

You can likely do that fairly readily with ctypes. Sorry, don't have
time to do more than point you at it tonight.

Good luck,
Mike
|

________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com
 
S

Simon Brunning

One of my students is interested in using Python to control his
(Windows) desktop, and wants to write a program to change the desktop
background or wallpaper. I told him I'd look into this, but I've had to
admit defeat.

I've been having a play in that area on and off. This isn't well
documented, but might get you started...

Can someone point me in the right direction, possibly post the simplest
Python program that can accomplish this. I understand this won't be
portable. At school, we use Win98SE; the student in question is using
XPHome at home, and I typically use Gentoo Linux/KDE 3.3. If there were
a single solution that would address all three environments, I'd be...
well, shocked.

Me too. ;-)
 
A

agarbutt

To do this on windows you need to import ctypes (which you may need to
download, http://starship.python.net/crew/theller/ctypes/) and win32con
(which you should have already but if not you can get it from
https://sourceforge.net/projects/pywin32/). to change th wall paper
use:

from ctypes import *
import win32con

windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, r'<path to
your bitmap>', SPIF_SENDWININICHANGE)

for further reference on SystemParametersInfoA goto:
http://msdn.microsoft.com/library/d...y/en-us/sysinfo/base/systemparametersinfo.asp

Hope this helps

Andy
Mediocre said:
Hello, all.

I'm teaching Python for the first time to some high school students, and
it's going well--Tomorrow's lesson: I'm going to show them how to use a
list comprehension to simplify a task.

One of my students is interested in using Python to control his
(Windows) desktop, and wants to write a program to change the desktop
 
M

Mediocre Person

Mediocre said:
One of my students is interested in using Python to control his
(Windows) desktop, and wants to write a program to change the desktop
background or wallpaper. I told him I'd look into this, but I've had to
admit defeat.

Thank to all for the replies--got the code working now.

Nick.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,209
Messages
2,571,088
Members
47,686
Latest member
scamivo

Latest Threads

Top