代码拉取完成,页面将自动刷新
# -*- 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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。