每天换一个新桌面的python

本文介绍了一个使用Python编写的脚本,该脚本可以自动从国家地理杂志的每日图片中下载图片,并将其设置为桌面壁纸。此脚本首先安装必要的Python库,然后通过解析网页源代码获取图片链接并下载图片。
This is a python snippet to set wallpaper as the photo of the day in national geographic.

1. install python form http://www.python.org/download/
2. install python image library(PLI) from http://www.pythonware.com/products/pil/
3. say the code below and run it by python

python 代码
 
  1. """ 
  2. Set the wallpaper as the picture got from national geographic picture of the day 
  3. by seasons@gmail.com 
  4. """  
  5. import ctypes  
  6. import Image  
  7. import calendar  
  8. import urllib  
  9. import socket  
  10.   
  11. STOREDIR = 'C:/lg_wallpaper/pod/'  
  12.   
  13. def setWallpaperFromBMP(imagepath):  
  14.     SPI_SETDESKWALLPAPER = 20 # According to http://support.microsoft.com/default.aspx?scid=97142  
  15.     ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, imagepath , 0) #SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE  
  16.   
  17. def setWallPaper(imagePath):  
  18.     """Given a path to an image, convert it to bmp and set it as wallpaper"""  
  19.     bmpImage = Image.open(imagePath)  
  20.     newPath = STOREDIR + 'mywallpaper.bmp'  
  21.     bmpImage.save(newPath, "BMP")  
  22.     setWallpaperFromBMP(newPath)  
  23.       
  24. def getPicture(fname):  
  25.     sock = urllib.urlopen("http://lava.nationalgeographic.com/pod/index.html")  
  26.     htmlSource = sock.read()  
  27.     sock.close()      
  28.     pos1 = htmlSource.find('sm_wallpaper')  
  29.     pos2 = htmlSource.find('/pod/pictures/normal')  
  30.     filename = htmlSource[pos1+13:pos2-12]  
  31.     fileurl = 'http://lava.nationalgeographic.com/pod/pictures/lg_wallpaper/'+filename  
  32.     urllib.urlretrieve(fileurl, fname)  
  33.     print 'got the picture from ' + fileurl  
  34.   
  35. def setWallpaperOfToday():  
  36.     filename = STOREDIR + str(calendar.datetime.date.today()) + '.jpg'  
  37.     print filename  
  38.     getPicture(filename)  
  39.     setWallPaper(filename)  
  40.      
  41. setWallpaperOfToday()  
  42. print 'Wallpaper set ok!'  
### 回答1: 我可以提供一些建议,但是要用python一个桌面课表,你需要学习一下python的基本编程知识。首先,你可以学习Python中的基本数据类型,如数字、字符串、列表和字典。然后,学习如何使用Python的标准库来操作文件和文件夹。最后,学习如何使用GUI(图形用户界面)工具来创建桌面应用程序,并为你的桌面课表设计一个简单的界面。 ### 回答2: 使用Python编写一个桌面课表可以借助于课表管理的库,如Pandas和tkinter。 首先,需要将课表的信息存储在一个Excel文件中,可以使用Pandas库读取和处理Excel数据。通过读取Excel文件,可以将课程时间、地点和其他相关信息提取出来。 接下来,使用tkinter库创建一个GUI界面,来展示课表信息。可以创建一个表格来显示每天的课程,并在每个时间段内显示对应的课程信息。可以使用tkinter的控件来创建表格,并将从Excel文件读取到的数据填充到表格中。 在GUI界面中,还可以添加一些其他的交互功能,比如添加的课程、修改课程信息、删除课程等操作。可以通过tkinter的控件,如Entry和Button,来实现用户输入课程信息并保存或更到Excel文件。 为了提高用户体验,可以给课程添加一些其他功能,比如设置提醒功能,让用户在上课之前收到提醒;或者添加搜索功能,让用户可以根据课程名称或教师姓名查找对应的课程。 总之,使用Python编写一个桌面课表可以借助于Pandas和tkinter库,通过读取Excel文件来获取课表信息,并使用tkinter创建一个用户友好的界面来展示和管理课程。 ### 回答3: 用Python编写一个桌面课表可以通过使用图形用户界面(GUI)开发库来实现,比如Tkinter。下面是一个简单的示例代码来展示如何使用Python和Tkinter编写一个基本的桌面课表: ```python import tkinter as tk class ScheduleApp: def __init__(self, root): self.root = root self.root.title("课表") # 创建一个文本框用于显示课程表信息 self.schedule_text = tk.Text(self.root) self.schedule_text.pack() # 创建一个按钮用于更课程表 update_btn = tk.Button(self.root, text="更课程表", command=self.update_schedule) update_btn.pack() def update_schedule(self): # 在这里可以编写代码来获取最的课程表信息,比如从数据库或者文件中读取 # 这里只是一个简单的示例,添加一些课程信息到文本框中 self.schedule_text.insert(tk.END, "星期一:\n") self.schedule_text.insert(tk.END, "9:00 - 10:30: 数学\n") self.schedule_text.insert(tk.END, "11:00 - 12:30: 英语\n") self.schedule_text.insert(tk.END, "\n星期二:\n") self.schedule_text.insert(tk.END, "9:00 - 10:30: 物理\n") self.schedule_text.insert(tk.END, "11:00 - 12:30: 化学\n") # 省略其他天的课程信息... # 创建根窗口 root = tk.Tk() # 创建课程表应用 schedule_app = ScheduleApp(root) # 启动主事件循环 root.mainloop() ``` 这个简单的示例代码使用了Tkinter库来创建了一个窗口,并在窗口中添加了一个文本框用于显示课程表信息。同时,还有一个“更课程表”按钮,点击该按钮会调用`update_schedule`方法来更课程表信息。在这个方法中,可以编写代码来获取最的课程表数据,并将其添加到文本框中显示。这个示例只是一个简单的实现,具体的课程表数据获取和显示的逻辑可以根据实际需求进行调整和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值