1 Star 0 Fork 0

月下独饮桃花醉/randomOne

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
randomOne.py 3.42 KB
一键复制 编辑 原始数据 按行查看 历史
月下独饮桃花醉 提交于 2021-10-08 13:11 . 代码提交
# -*- coding: UTF-8 -*-
import webbrowser
textFile = open('./class.txt', "r", encoding='utf-8')
lines = textFile.readlines()
textFile.close()
htmlName = 'class.html'
html = open("./" + htmlName, "w", encoding='utf-8')
html.write("<!DOCTYPE html>\n" +
"<html lang=\"en\">\n" +
"<head>\n" +
" <meta charset=\"UTF-8\">\n" +
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" +
" <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n" +
" <title>随机点名</title>\n" +
" <style>\n" +
" #content{\n" +
" width: 600px;\n" +
" height: 400px;\n" +
" background: antiquewhite;\n" +
" margin: 100px auto;\n" +
" text-align: center;\n" +
" position: relative;\n" +
" line-height: 300px;\n" +
" color: hotpink;\n" +
" font-size: 70px;\n" +
" } \n" +
" #btn1{\n" +
" background: #ccc;\n" +
" width: 180px;\n" +
" height: 80px;\n" +
" font-size: 30px;\n" +
" color: #f40;\n" +
" border-radius: 12px;\n" +
" position: absolute;\n" +
" bottom: 30px;\n" +
" left: 50%;\n" +
" margin-left: -90px;\n" +
" \n" +
" }\n" +
" \n" +
" </style>\n" +
"</head>\n" +
"<body>\n" +
" <div id=\"content\">\n" +
" <span id=\"span1\">\n" +
" 点击开始\n" +
" </span>\n" +
" <button id=\"btn1\">\n" +
" 开始\n" +
" </button>\n" +
"\n" +
" </div>\n" +
" <script>\n" +
" var arr = [")
for line in lines:
html.write("'" + line.strip() + "',")
html.write("];\n" +
" \n" +
" var $btn1 = document.getElementById('btn1');\n" +
" var $content = document.getElementById('content');\n" +
" var $span1 = document.getElementById('span1');\n" +
" var timer;//计时器\n" +
" var testNum = true;\n" +
" $btn1.onclick = function(){\n" +
" if(testNum){\n" +
" // console.log(1);\n" +
" start();\n" +
" $btn1.innerHTML = '停止';\n" +
" testNum = false;\n" +
" }\n" +
" else{\n" +
" // console.log(0);\n" +
" stop();\n" +
" $btn1.innerHTML = '开始';\n" +
" testNum = true;\n" +
" }\n" +
" }\n" +
" function start(){\n" +
" timer = setInterval(function(){\n" +
" var num = random(0,arr.length - 1);\n" +
" $span1.innerHTML = arr[num];\n" +
" },50)\n" +
" }\n" +
" function stop(){\n" +
" clearInterval(timer); \n" +
" }\n" +
" // 随机函数\n" +
" function random(a,b){\n" +
" var randomNum = Math.round(Math.random() * (b - a) + a);\n" +
" return randomNum;\n" +
" } \n" +
" </script>\n" +
"</body>\n" +
"</html>")
html.close()
webbrowser.open_new_tab(htmlName)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/Ricardo_M_Lu/random-one.git
git@gitee.com:Ricardo_M_Lu/random-one.git
Ricardo_M_Lu
random-one
randomOne
master

搜索帮助