1、抖音同款,不同意不许走
源码:love.py
# coding: utf8
from tkinter import *
from tkinter import messagebox
import random
def no_close():
return
#关闭所有窗口
def close_all_window():
window.destroy()
#关闭窗口提示
def close_window():
messagebox.showinfo(title="不要嘛~", message="不选好不许走!")
#“好的”窗口
def Love():
love = Toplevel(window)
love.geometry("300x100+580+250")
love.title("爱你么么哒~")
btn = Button(love, text="在一起!", width=10, height=2, command=close_all_window)
btn.place(x=100, y=30)
love.protocol("WM_DELETE_WINDOW", no_close)
window = Tk()
window.title("嗨,小姐姐") #窗口标题
window.geometry("360x640+550+50") #窗口大小
window.protocol("WM_DELETE_WINDOW", close_window) #窗口关闭
label = Label(window, text="观察你很久了", font=("微软雅黑", 18))
label.place(x=120, y=50)
label = Label(window, text="做我女朋友好不好?", font=("微软雅黑", 24))
label.place(x=70, y=100)
btn1 = Button(window, text="好", width=15, height=2, command=Love)
btn1.place(x=110, y=200)
# “不好”按钮
pos = [110, 300]
btn2 = Button(window, text="不好", width=15, height=2)
btn2.place(x=pos[0], y=pos[1])
def on_enter(e):
global pos
dx = random.randint(100, 200)
dy = random.randint(100, 300)
print(pos,dx,dy)
pos = (pos[0] + dx) % 200, (pos[1] - 250 + dy) % 350 + 250
btn2.place(x=pos[0], y=pos[1])
btn2.bind("<Enter>", on_enter)
#显示窗口,消息循坏
window.mainloop()
运行效果:
2、阿狸桃子爱情表白
文件有点大,截图不方便,需要全部文件及源码私信。
源码:love.html
<!DOCTYPE html>
<!--[if IE 6]>
<html id="ie6" class="ie ie6 lt-ie9">
<![endif]-->
<!--[if IE 7]>
<html id="ie7" class="ie ie7 lt-ie9">
<![endif]-->
<!--[if IE 8]>
<html id="ie8" class="ie ie8 lt-ie9">
<![endif]-->
<!--[if gte IE 9]>
<html class="ie ie9">
<![endif]-->
<!--[if !(IE)]><!-->
<html><!--<![endif]--><head>
<title>我们的回忆</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="Pragma" content="no-cache">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="love2/all.css" tppabs="love2/all.min.css">
</head>
<body class="ft-absolute-nav">
<div style="transform: translateX(0%) translateY(0%);" class="flowtime no-transition">
<div id="" data-prog="__1" class="ft-section section-1" data-id="__section-1">
<div data-prog="__1" id="" class="ft-page page-1 hilite actual" data-id="__page-1">
<p class="text1"><span id="text-75" contenteditable="true">他</span> ❤ <span id="text-76" contenteditable="true">她</span> <span id="text-77" contenteditable="true">一生一世</span></p>
<p class="text2">按键盘 "↓" <span id="text-78" contenteditable="true">开始倾听我的表白</span></p>
</div>
<div data-prog="__2" id="" class="ft-page page-2 future-page" data-id="__page-2">
<p class="top-text" id="text-1" contenteditable="true">过去的他一直是一个人生活,享受着孤独,也憧憬着爱情。</p>
<img src="love2/iali63.jpg" alt="过去的小明一直是一个人生活,享受着孤独,也憧憬着爱情。">
</div>
<div data-prog="__3" id="" class="ft-page page-3 left-img future-page" data-id="__page-3">
<h2 class="text" id="text-2" contenteditable="true">一个人的长廊</h2>
<img src="love2/iali35.jpg" alt="一个人的长廊">
</div>
<div data-prog="__4" id="" class="ft-page page-4 full-img future-page" data-id="__page-4">
<h2 class="center-text" id="text-3" contenteditable="true">一个人的山岗</h2>
<img src="love2/iali6.jpg" alt="一个人的山岗">
</div>
</div>
<div id="" data-prog="__2" class="ft-section section-2" data-id="__section-2">
<div data-prog="__1" id="" class="ft-page page-5 full-img future-section" data-id="__page-1">
<h2 class="center-text" id="text-4" contenteditable="true">一个人的地铁</h2>
<img src="love2/iali19.jpg" alt="一个人的地铁">
</div>
<div data-prog="__2" id="" class="ft-page page-6 future-section future-page" data-id="__page-2">
<h2 class="center-text" id="text-5" contenteditable="true">一个人的游乐场</h2>
<img src="love2/iali29.jpg" alt="一个人的游乐场">
</div>
<div data-prog="__3" id="" class="ft-page page-7 future-section future-page" data-id="__page-3">
<h3 id="text-6" contenteditable="true">但他依然乐观,微笑着,等待着</h3>
<img src="love2/iali60.jpg" alt="但他依然乐观,微笑着,等待着">
</div>
<div data-prog="__4" id="" class="ft-page page-8 full-img future-section future-page" data-id="__page-4">
<h3 id="text-7" contenteditable="true">生活难免有风风雨雨</h3>
<img src="love2/iali51.jpg" alt="生活难免有风风雨雨">
</div>
<div data-prog="__5" id="" class="ft-page page-9 future-section future-page" data-id="__page-5">
<h3 id="text-8" contenteditable="true">他总是能够轻松的应对</h3>
<img src="love2/iali5.jpg">
</div>
<div data-prog="__6" id="" class="ft-page page-10 future-section future-page" data-id="__page-6">
<h3 id="text-9" contenteditable="true">并且面带阳光、自信的笑容</h3>
<img src="love2/iali22.jpg">
</div>
</div>
<div id="" data-prog="__3" class="ft-section section-3" data-id="__section-3">
<div data-prog="__1" id="" class="ft-page page-11 full-img future-section" data-id="__page-1">
<h3 id="text-10" contenteditable="true">生活也不会总是一帆风顺</h3>
<img src="love2/iali24.jpg">
</div>
<div data-prog="__2" id="" class="ft-page page-12 future-section future-page" data-id="__page-2">
<h3><span id="text-11" contenteditable="true">但他每次都能勇敢的面对</span><br><span id="text-12" contenteditable="true">随时准备接受生活的挑战</span></h3>
<img src="love2/iali25.jpg">
</div>
<div data-prog="__3" id="" class="ft-page page-13 future-section future-page" data-id="__page-3">
<img src="love2/iali64.jpg" alt="可是小明的爱情又在哪里呢?">
<h3 id="text-13" contenteditable="true">可是他的爱情又在哪里呢?</h3>
</div>
<div data-prog="__4" id="" class="ft-page page-14 left-img future-section future-page" data-id="__page-4">
<h3 id="text-14" contenteditable="true">在镜子里面吗?他不敢相信</h3>
<img src="love2/iali46.jpg">
</div>
<div data-prog="__5" id="" class="ft-page page-15 left-img future-section future-page" data-id="__page-5">
<h3><span id="text-15" contenteditable="true">他去问大树,我的爱情在哪里?</span><br><span id="text-16" contenteditable="true">大树告诉他,也许就在不远的地方</span></h3>
<img src="love2/iali45.jpg">
</div>
<div data-prog="__6" id="" class="ft-page page-16 left-img future-section future-page" data-id="__page-6">
<h3><span id="text-17" contenteditable="true">于是,他一个人继续向前走</span><br><span id="text-18" contenteditable="true">走在茫茫的雪地上</span></h3>
<img src="love2/iali66.jpg">
</div>
<div data-prog="__7" id="" class="ft-page page-17 top-text future-section future-page" data-id="__page-7">
<h3 id="text-19" contenteditable="true">直到有一天他与她相遇了</h3>
<img src="love2/iali16.jpg">
</div>
</div>
<div id="" data-prog="__4" class="ft-section section-4" data-id="__section-4">
<div data-prog="__1" id="" class="ft-page page-18 full-img future-section" data-id="__page-1">
<p class="text" id="text-20" contenteditable="true">他喜欢她,因为她的出现,他脸上有了更加灿烂的笑容</p>
<img src="love2/iali11.jpg">
</div>
<div data-prog="__2" id="" class="ft-page page-19 future-section future-page" data-id="__page-2">
<h3 id="text-21" contenteditable="true">可是她会喜欢他吗?</h3>
<img src="love2/iali75.jpg">
</div>
<div data-prog="__3" id="" class="ft-page page-20 future-section future-page" data-id="__page-3">
<img src="love2/iali59.png" tppabs="http://kingzs70.oss.aliyuncs.com/iali/img/iali59.png">
<h3 id="text-22" contenteditable="true">终于有一天,他鼓起了勇气</h3>
<img src="love2/iali9.jpg">
</div>
<div data-prog="__4" id="" class="ft-page page-21 future-section future-page" data-id="__page-4">
<h3 id="text-23" contenteditable="true">他好高兴</h3>
<img src="love2/iali59_002.png">
</div>
<div data-prog="__5" id="" class="ft-page page-22 left-img future-section future-page" data-id="__page-5">
<h3 id="text-24" contenteditable="true">每天他都会去找她</h3>
<img src="love2/iali4.jpg">
</div>
<div data-prog="__6" id="" class="ft-page page-23 left-img future-section future-page" data-id="__page-6">
<h3 id="text-25" contenteditable="true">然后两个人一起出去玩</h3>
<img src="love2/iali44.jpg">
</div>
<div data-prog="__7" id="" class="ft-page page-24 full-img future-section future-page" data-id="__page-7">
<h3 id="text-26" contenteditable="true">晚上他会把她送回家</h3>
<img src="love2/iali32.jpg">
</div>
</div>
<div id="" data-prog="__5" class="ft-section section-5" data-id="__section-5">
<div data-prog="__1" id="" class="ft-page page-25 left-img future-section" data-id="__page-1">
<h3><span id="text-27" contenteditable="true">直到很晚</span><br><span id="text-28" contenteditable="true">他才会一个人回家</span></h3>
<img src="love2/iali37.jpg">
</div>
<div data-prog="__2" id="" class="ft-page page-26 top-text future-section future-page" data-id="__page-2">
<h3 id="text-29" contenteditable="true">然后高兴地进入梦乡,希望梦到她</h3>
<img src="love2/iali10.gif">
</div>
<div data-prog="__3" id="" class="ft-page page-27 future-section future-page" data-id="__page-3">
<h3 id="text-30" contenteditable="true">他很快就成为了她的逛街助手</h3>
<img src="love2/iali67.jpg">
</div>
<div data-prog="__4" id="" class="ft-page page-28 future-section future-page" data-id="__page-4">
<h3 id="text-31" contenteditable="true">他和她一起去了好多地方玩</h3>
<img src="love2/iali40.jpg">
</div>
<div data-prog="__5" id="" class="ft-page page-29 future-section future-page" data-id="__page-5">
<h3 id="text-32" contenteditable="true">他也和她一样成为了一个吃货</h3>
<img src="love2/iali12.jpg">
</div>
<div data-prog="__6" id="" class="ft-page page-30 future-section future-page" data-id="__page-6">
<h3 id="text-33" contenteditable="true">后来,他们搬到了一起</h3>
<img src="love2/iali76.gif">
</div>
<div data-prog="__7" id="" class="ft-page page-31 future-section future-page" data-id="__page-7">
<h3 id="text-34" contenteditable="true">于是他开始学习新的技能</h3>
<img src="love2/iali77.jpg">
</div>
</div>
<div id="" data-prog="__6" class="ft-section section-6" data-id="__section-6">
<div data-prog="__1" id="" class="ft-page page-32 future-section" data-id="__page-1">
<h3 id="text-35" contenteditable="true">煮饭</h3>
<img src="love2/iali62.jpg">
</div>
<div data-prog="__2" id="" class="ft-page page-33 top-text future-section future-page" data-id="__page-2">
<h3 id="text-36" contenteditable="true">每天早上,他们吃着自己做的美食</h3>
<img src="love2/iali3.jpg">
</div>
<div data-prog="__3" id="" class="ft-page page-34 left-img future-section future-page" data-id="__page-3">
<h3 id="text-37" contenteditable="true">然后在同一个站台,高高兴兴的一起上班</h3>
</div>
<div data-prog="__4" id="" class="ft-page page-35 future-section future-page" data-id="__page-4">
<h3><span id="text-38" contenteditable="true">他感觉自己好幸福。</span><br><span id="text-39" contenteditable="true">因为自己有了家</span><br><span id="text-40" contenteditable="true">那个有她在的地方</span></h3>
<img src="love2/iali8.gif">
</div>
<div data-prog="__5" id="" class="ft-page page-36 full-img future-section future-page" data-id="__page-5">
<h3 id="text-41" contenteditable="true">他们偶尔也会吵架</h3>
<img src="love2/iali31.jpg">
</div>
<div data-prog="__6" id="" class="ft-page page-37 left-img future-section future-page" data-id="__page-6">
<h3 id="text-42" contenteditable="true">他不想这样</h3>
<img src="love2/iali49.jpg">
</div>
<div data-prog="__7" id="" class="ft-page page-38 bottom-text future-section future-page" data-id="__page-7">
<img src="love2/iali21.jpg">
<h3 id="text-43" contenteditable="true">一定是我有什么做的不对,他在想</h3>
</div>
</div>
<div id="" data-prog="__7" class="ft-section section-7" data-id="__section-7">
<div data-prog="__1" id="" class="ft-page page-39 left-img future-section" data-id="__page-1">
<h3 id="text-44" contenteditable="true">如果没有她在身边,窗外就没有风景</h3>
<img src="love2/iali2.jpg">
</div>
<div data-prog="__2" id="" class="ft-page page-40 future-section future-page" data-id="__page-2">
<h3 id="text-45" contenteditable="true">如果没有她在身后</h3>
<img src="love2/iali14.jpg">
</div>
<div data-prog="__3" id="" class="ft-page page-41 future-section future-page" data-id="__page-3">
<img src="love2/iali30_1.jpg" class="img1">
<img src="love2/iali30_2.jpg" class="img2">
<h3 id="text-46" contenteditable="true"> 他又怎会飞的更高更远</h3>
</div>
<div data-prog="__4" id="" class="ft-page page-42 future-section future-page" data-id="__page-4">
<h3><span id="text-47" contenteditable="true">他不想这样。他要为她改变自己</span><br><span id="text-48" contenteditable="true">她说她喜欢狮子座的人,于是他许下愿望</span></h3>
<img src="love2/iali69.jpg">
</div>
<div data-prog="__5" id="" class="ft-page page-43 future-section future-page" data-id="__page-5">
<img src="love2/iali42.jpg">
<h3 id="text-49" contenteditable="true">我愿为你变成狮子座</h3>
</div>
<div data-prog="__6" id="" class="ft-page page-44 left-img future-section future-page" data-id="__page-6">
<h3><span id="text-50" contenteditable="true">爱情就像花草一样</span><br><span id="text-51" contenteditable="true">需要用包容来浇灌</span></h3>
<img src="love2/iali0.jpg">
</div>
<div data-prog="__7" id="" class="ft-page page-45 left-img future-section future-page" data-id="__page-7">
<h3><span id="text-52" contenteditable="true">再到后来,她要过生日了</span><br><span id="text-53" contenteditable="true">他开始为她准备礼物</span></h3>
<img src="love2/iali18.jpg">
</div>
</div>
<div id="" data-prog="__8" class="ft-section section-8" data-id="__section-8">
<div data-prog="__1" id="" class="ft-page page-46 future-section" data-id="__page-1">
<img src="love2/iali57.gif">
<h3>
<span id="text-54" contenteditable="true">看着礼物一件件准备好了</span>
<span id="text-55" contenteditable="true">他好开心</span>
<span id="text-56" contenteditable="true">因为他想象着她收到礼物时</span>
<span id="text-57" contenteditable="true">开心的样子</span>
</h3>
</div>
<div data-prog="__2" id="" class="ft-page page-47 top-text future-section future-page" data-id="__page-2">
<img src="love2/iali58.jpg">
<h3>
<span id="text-58" contenteditable="true">想想后面还有一辈子</span>
<span id="text-59" contenteditable="true">他好开心</span>
<span id="text-60" contenteditable="true">因为可以和她</span>
<span id="text-61" contenteditable="true">去全世界好多地方玩</span></h3>
</div>
<div data-prog="__3" id="" class="ft-page page-48 left-img future-section future-page" data-id="__page-3">
<p><span id="text-62" contenteditable="true">他也会继续努力</span><br><span id="text-63" contenteditable="true">为了他和她的梦之城堡</span></p>
<img src="love2/iali65.jpg">
</div>
<div data-prog="__4" id="" class="ft-page page-49 full-img future-section future-page" data-id="__page-4">
<img src="love2/iali71.jpg">
<p class="text">
<span class="text" id="text-64" contenteditable="true">他很幸福,因为他找到了她。他相信后面的每天都会是快乐的</span><br>
<span class="text" id="text-65" contenteditable="true">简简单单,体会着与她在一起的每一个刻</span>
</p>
</div>
<div data-prog="__5" id="" class="ft-page page-50 future-section future-page" data-id="__page-5">
<p class="text" id="text-66" contenteditable="true">后来的一天,她说她不敢坐山车了,于是他就带她到别的地方玩。这只是他们幸福生活中的一件小事,小到无法引起别人的注意。可这是属于他和她的幸福生活。</p>
<img src="love2/iali50_1.jpg" class="img1">
<img src="love2/iali50_2.jpg" class="img2">
</div>
<div data-prog="__6" id="" class="ft-page page-51 future-section future-page" data-id="__page-6">
<p>
<span id="text-67" contenteditable="true">她:永远有多远?</span><br>
<span id="text-68" contenteditable="true">他:比时间多一秒就是永远,我会永远爱你</span><br>
<span id="text-69" contenteditable="true">她:世界有多大?</span><br>
<span id="text-70" contenteditable="true">他:你走到哪里,世界就有多大</span>
</p>
</div>
</div>
<div id="" data-prog="__9" class="ft-section section-9" data-id="__section-9">
<div data-prog="__1" id="" class="ft-page page-52 full-img future-section" data-id="__page-1">
<h3 id="text-71" contenteditable="true">愿得一人心,白首不相离</h3>
<img src="love2/iali20.jpg">
</div>
<div data-prog="__2" id="" class="ft-page page-53 future-section future-page" data-id="__page-2">
<img src="love2/iali68.jpg" alt="happy birthday">
<h6 id="text-72" contenteditable="true">亲爱的</h6>
<h3 id="text-73" contenteditable="true">永远爱你</h3>
</div>
<div data-prog="__3" id="" class="ft-page page-54 center-img future-section future-page" data-id="__page-3">
<div class="center-img">I love you</div>
</div>
<div data-prog="__4" id="" class="ft-page page-55 right-img future-section future-page" data-id="__page-4">
<img src="love2/14915.jpg">
<p class="text">
<span id="text-74" contenteditable="true">他和她的故事会一直继续下去。</span><br>
<span id="text-75" contenteditable="true">无论精彩、平淡都会是他们喜欢的。</span><br>
<span id="text-76" contenteditable="true"></span><br>
<span id="text-77" contenteditable="true">亲爱的,按"Esc"键将有惊喜♥♥</span><br>
<br>
<br>
</p>
</div>
</div>
</div>
<noscript><div class="nojavascript">您的浏览器禁用了javascript,无法正常浏览本页面</div></noscript>
<audio autoplay="autopaly">
<source src="http://qzone.haoduoge.com/up/1/MTgzMDk4MDA=.mp3" type="audio/mp3" />
</audio>
<script src="love2/jquery.js"></script>
<script src="love2/all.js" tppabs="http://aijava.cn/demo/love/2014/js/all.min.js"></script>
<script src="love2/love.js" tppabs="http://aijava.cn/demo/love/2014/js/love.min.js"></script><div class="ft-default-progress"><div class="ft-section-thumb thumb-section-0" data-section="__0"><div data-page="__0" data-section="__0" class="ft-page-thumb thumb-page-0 actual"></div><div data-page="__1" data-section="__0" class="ft-page-thumb thumb-page-1"></div><div data-page="__2" data-section="__0" class="ft-page-thumb thumb-page-2"></div><div data-page="__3" data-section="__0" class="ft-page-thumb thumb-page-3"></div></div><div class="ft-section-thumb thumb-section-1" data-section="__1"><div data-page="__0" data-section="__1" class="ft-page-thumb thumb-page-0"></div><div data-page="__1" data-section="__1" class="ft-page-thumb thumb-page-1"></div><div data-page="__2" data-section="__1" class="ft-page-thumb thumb-page-2"></div><div data-page="__3" data-section="__1" class="ft-page-thumb thumb-page-3"></div><div data-page="__4" data-section="__1" class="ft-page-thumb thumb-page-4"></div><div data-page="__5" data-section="__1" class="ft-page-thumb thumb-page-5"></div></div><div class="ft-section-thumb thumb-section-2" data-section="__2"><div data-page="__0" data-section="__2" class="ft-page-thumb thumb-page-0"></div><div data-page="__1" data-section="__2" class="ft-page-thumb thumb-page-1"></div><div data-page="__2" data-section="__2" class="ft-page-thumb thumb-page-2"></div><div data-page="__3" data-section="__2" class="ft-page-thumb thumb-page-3"></div><div data-page="__4" data-section="__2" class="ft-page-thumb thumb-page-4"></div><div data-page="__5" data-section="__2" class="ft-page-thumb thumb-page-5"></div><div data-page="__6" data-section="__2" class="ft-page-thumb thumb-page-6"></div></div><div class="ft-section-thumb thumb-section-3" data-section="__3"><div data-page="__0" data-section="__3" class="ft-page-thumb thumb-page-0"></div><div data-page="__1" data-section="__3" class="ft-page-thumb thumb-page-1"></div><div data-page="__2" data-section="__3" class="ft-page-thumb thumb-page-2"></div><div data-page="__3" data-section="__3" class="ft-page-thumb thumb-page-3"></div><div data-page="__4" data-section="__3" class="ft-page-thumb thumb-page-4"></div><div data-page="__5" data-section="__3" class="ft-page-thumb thumb-page-5"></div><div data-page="__6" data-section="__3" class="ft-page-thumb thumb-page-6"></div></div><div class="ft-section-thumb thumb-section-4" data-section="__4"><div data-page="__0" data-section="__4" class="ft-page-thumb thumb-page-0"></div><div data-page="__1" data-section="__4" class="ft-page-thumb thumb-page-1"></div><div data-page="__2" data-section="__4" class="ft-page-thumb thumb-page-2"></div><div data-page="__3" data-section="__4" class="ft-page-thumb thumb-page-3"></div><div data-page="__4" data-section="__4" class="ft-page-thumb thumb-page-4"></div><div data-page="__5" data-section="__4" class="ft-page-thumb thumb-page-5"></div><div data-page="__6" data-section="__4" class="ft-page-thumb thumb-page-6"></div></div><div class="ft-section-thumb thumb-section-5" data-section="__5"><div data-page="__0" data-section="__5" class="ft-page-thumb thumb-page-0"></div><div data-page="__1" data-section="__5" class="ft-page-thumb thumb-page-1"></div><div data-page="__2" data-section="__5" class="ft-page-thumb thumb-page-2"></div><div data-page="__3" data-section="__5" class="ft-page-thumb thumb-page-3"></div><div data-page="__4" data-section="__5" class="ft-page-thumb thumb-page-4"></div><div data-page="__5" data-section="__5" class="ft-page-thumb thumb-page-5"></div><div data-page="__6" data-section="__5" class="ft-page-thumb thumb-page-6"></div></div><div class="ft-section-thumb thumb-section-6" data-section="__6"><div data-page="__0" data-section="__6" class="ft-page-thumb thumb-page-0"></div><div data-page="__1" data-section="__6" class="ft-page-thumb thumb-page-1"></div><div data-page="__2" data-section="__6" class="ft-page-thumb thumb-page-2"></div><div data-page="__3" data-section="__6" class="ft-page-thumb thumb-page-3"></div><div data-page="__4" data-section="__6" class="ft-page-thumb thumb-page-4"></div><div data-page="__5" data-section="__6" class="ft-page-thumb thumb-page-5"></div><div data-page="__6" data-section="__6" class="ft-page-thumb thumb-page-6"></div></div><div class="ft-section-thumb thumb-section-7" data-section="__7"><div data-page="__0" data-section="__7" class="ft-page-thumb thumb-page-0"></div><div data-page="__1" data-section="__7" class="ft-page-thumb thumb-page-1"></div><div data-page="__2" data-section="__7" class="ft-page-thumb thumb-page-2"></div><div data-page="__3" data-section="__7" class="ft-page-thumb thumb-page-3"></div><div data-page="__4" data-section="__7" class="ft-page-thumb thumb-page-4"></div><div data-page="__5" data-section="__7" class="ft-page-thumb thumb-page-5"></div></div><div class="ft-section-thumb thumb-section-8" data-section="__8"><div data-page="__0" data-section="__8" class="ft-page-thumb thumb-page-0"></div><div data-page="__1" data-section="__8" class="ft-page-thumb thumb-page-1"></div><div data-page="__2" data-section="__8" class="ft-page-thumb thumb-page-2"></div><div data-page="__3" data-section="__8" class="ft-page-thumb thumb-page-3"></div></div></div>
<div class="mPower"><span id="on" title="点击暂停"></span><span id="off" title="点击播放"></span></div>
<div style="display:none">
<script type="text/javascript">var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol +
"hm.baidu.com/h.js%3F016f5d60f3fb81c4ce4a180a4caec134' type='text/javascript'%3E%3C/script%3E"));
</script><script src="love2/h.js" type="text/javascript"></script>
<script type="text/javascript">
var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cspan id='cnzz_stat_icon_5796950'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s13.cnzz.com/stat.php%3Fid%3D5796950%26show%3Dpic1' type='text/javascript'%3E%3C/script%3E"));
</script><span id="cnzz_stat_icon_5796950"><a href="http://www.cnzz.com/stat/website.php?web_id=5796950" target="_blank" title="站长统计"><img src="love2/pic1.gif" border="0" hspace="0" vspace="0"></a></span><script src="love2/stat.php" type="text/javascript"></script><script src="love2/core.php" charset="utf-8" type="text/javascript"></script>
</div>
</body></html>
部分效果:
3、词云版表白
文件结构:
font为字体,image为背景图模板,可以自备,也可以私信或评论我发。
love.txt和stopwords.txt为词云文本。
word.py为主程序。
源码:
#coding:utf-8
from os import path
from scipy.misc import imread
import matplotlib.pyplot as plt
import jieba
from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator
stopwords = {}
def importStopword(filename=''):
global stopwords
f = open(filename, 'r', encoding='utf-8')
line = f.readline().rstrip()
while line:
stopwords.setdefault(line, 0)
stopwords[line] = 1
line = f.readline().rstrip()
f.close()
def processChinese(text):
seg_generator = jieba.cut(text) # 使用结巴分词,也可以不使用
seg_list = [i for i in seg_generator if i not in stopwords]
seg_list = [i for i in seg_list if i != u' ']
seg_list = r' '.join(seg_list)
return seg_list
importStopword(filename='./stopwords.txt')
# 获取当前文件路径
# __file__ 为当前文件, 在ide中运行此行会报错,可改为
# d = path.dirname('.')
d = path.dirname(__file__)
text = open(path.join(d, 'love.txt'),encoding ='utf-8').read()
#如果是中文
text = processChinese(text)#中文不好分词,使用Jieba分词进行
# read the mask / color image
# taken from http://jirkavinse.deviantart.com/art/quot-Real-Life-quot-Alice-282261010
# 设置背景图片
back_coloring = imread(path.join(d, "./image/love.jpg"))
wc = WordCloud( font_path='./font/叶立群几何体.ttf',#设置字体
background_color="black", #背景颜色
max_words=2000,# 词云显示的最大词数
mask=back_coloring,#设置背景图片
#max_font_size=100, #字体最大值
random_state=42,
)
# 生成词云, 可以用generate输入全部文本(中文不好分词),也可以我们计算好词频后使用generate_from_frequencies函数
wc.generate(text)
# wc.generate_from_frequencies(txt_freq)
# txt_freq例子为[('词a', 100),('词b', 90),('词c', 80)]
# 从背景图片生成颜色值
image_colors = ImageColorGenerator(back_coloring)
plt.figure()
# 以下代码显示图片
plt.imshow(wc)
plt.axis("off")
plt.show()
# 绘制词云
'''plt.figure()
# recolor wordcloud and show
# we could also give color_func=image_colors directly in the constructor
plt.imshow(wc.recolor(color_func=image_colors))
plt.axis("off")
# 绘制背景图片为颜色的图片
plt.figure()
plt.imshow(alice_coloring, cmap=plt.cm.gray)
plt.axis("off")
plt.show()
'''
# 保存图片
wc.to_file(path.join(d, "名称.png"))
运行效果图:
若出现报错:cannot import name ‘imread’ from ‘scipy.misc’
解决办法见:ImportError: cannot import name ‘imread’ from ‘scipy.misc’ 解决办法
因为每次在本文更新后,CSDN都会审核一段时间才能发出来,所以新开一文更新。