亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用python顯示google圖表并每10秒刷新一次數據

使用python顯示google圖表并每10秒刷新一次數據

慕田峪9158850 2023-12-05 15:21:06
我需要使用 python 和每 10 秒隨機 2 個整數顯示 google 圖表,將整數替換到圖表中,然后顯示在瀏覽器上。這是我的代碼,我是 python 新手,不知道我的代碼有什么問題import randomimport timewhile True:     f = open('message.html', 'w')     message1 = '<html><head><script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script><script type="text/javascript">'     message2 = "google.charts.load('current', {'packages':['corechart']});google.charts.setOnLoadCallback(drawChart);function drawChart() {var data = google.visualization.arrayToDataTable([          ['Task', 'Hours per Day'],"     message3 = "['Work', "     message4 = "],           ['Sleep',"     message5 = "]]);var options = {title: 'My Daily Activities'};var chart = new google.visualization.PieChart(document.getElementById('piechart'));chart.draw(data, options);}</script></head><body>"     message6 = '<div id="piechart" style="width: 900px; height: 500px;"></div></body></html>'     a = random.randint(0, 101)     b = random.randint(0, 101)     message = message1 + message2 + message3 + str(a) + message4 + str(b) + message5 + message6     f.write(message)     time.sleep(10)     f.close()我嘗試在終端中打印 a 和 b,它完全隨機,但圖表沒有顯示在瀏覽器上。
查看完整描述

1 回答

?
飲歌長嘯

TA貢獻1951條經驗 獲得超3個贊

你可以在那里編寫并重新加載 html 以在 10 秒后查看結果:


 f.write(message)

 f.close()

 time.sleep(10)


查看完整回答
反對 回復 2023-12-05
  • 1 回答
  • 0 關注
  • 147 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號