我对任何开发都是新手。因此,如果我错过了一些非常琐碎的东西,我提前道歉。
我在ubuntu和raspbian上实现了pywebview,现在我正尝试在MacOS上实现它。测试平台为Catalina 10.15.5。
我正在运行的代码:
import os
import webview
def get_ip(self):
raw_ip = os.popen('curl https://ipinfo.io/ip').read()
local_ip = raw_ip.replace('\n','')
response = {"ip": local_ip}
return response
window = webview.create_window('PyWebView Test', 'https://website.com/index.html', js_api=api, width=1024, height=768)在这个html页面上,我尝试显示本地机器的公网IP:
所以在我运行的html中是:
<html>
<body>
<h2 class="text">Current IP:</h2>
<h2 class="text" id="local_ip"></h2>
</body>
<script>
$(function getipaddress(){
$(document).ready(function () {
pywebview.api.get_ip().then(function(response) {
window.local_ip = response.ip;
$('#local_ip').html(window.local_ip);
})
});
});
</script>
</html>当我在本地运行这段代码时,
window = webview.create_window('PyWebView Test', './index.html', js_api=api, width=1024, height=768)当index.html在同一文件夹中时,我可以看到显示的IP地址,这是所需的。
我寻找了一个解决方案,我找到了一个看起来很接近的this,但我不知道如何实现这个修复。但是找不到我需要的东西,请帮帮我!
发布于 2020-08-09 22:51:53
在HTML端的JS中,添加了鼠标移动功能,并且工作正常,这对于我的用例是可以接受的。
https://stackoverflow.com/questions/62501059
复制相似问题