python做一个写诗歌的网页
picture下面保存的网站壁纸图片
txt保存的所有的诗歌信息
下面的主页信息index.html
<!DOCTYPE HTML>
<html>
<title>作蚕丝[南北朝-佚名].txt</title>
<meta charset="gbk">
<meta http-equiv = "refresh" content="9" />
<head>
<style>
*{
padding:0px;
margin:0px;
}
body{
background:url(picture/2016年Bing夜景主题桌面壁纸.jpg)
}
.nav{
width:auto;
height:auto;
border-radius:5px;
font-size:25px;
font-weight:bold;
background:#ccc;
opacity:.8;
text-align:center;
}
</style>
</head>
<body>
<div class="nav">春蚕不应老,昼夜常怀丝。
何惜微躯尽,缠绵自有时</div>
</body>
</html>
重点在python中
# -*- coding:utf-8 -*-
import os,sys
from time import sleep
f = os.listdir('txt/')
img = os.listdir('picture/')
img_i = 0
flag = False
while True:
i=0
if img_i>=616:
img_i=0
for ss in f:
name = ss
co = open('txt/%s'%ss,'r')
cont = co.read()
cont = cont.replace('[','')
cont = cont.replace(']','')
imgbg = 'picture/%s' % img[img_i]
str = '''
<!DOCTYPE HTML>
<html>
<title>%s</title>
<meta charset="gbk">
<meta http-equiv = "refresh" content="9" />
<head>
<style>
*{
padding:0px;
margin:0px;
}
body{
background:url(%s)
}
.nav{
width:auto;
height:auto;
border-radius:5px;
font-size:25px;
font-weight:bold;
background:#ccc;
opacity:.8;
text-align:center;
}
</style>
</head>
<body>
<div class="nav">%s</div>
</body>
</html>
'''%(name,imgbg,cont)
f = open('index.html','w+')
f.write(str)
f.close()
if not flag:
os.system('start index.html')
flag = True
print(' 现在的诗歌是 : [%s]'%name)
sleep(10)
i+=1
img_i+=1
if img_i>=616:
img_i=0
说白了是不是很简单,不过也很养眼
可以看到,网页上的诗歌过几秒会自动刷新切换显示,然后在python后台会提示是什么诗歌。
来源:CSDN
作者:码来的小朋友
链接:https://blog.csdn.net/qq_25755645/article/details/104689232