最简单的 pyjs (pyjamas) 应用程序中的空白页

2024-05-15 15:01:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用睡衣(http://pyjs.org/)。我的输入文件,名为嗨,py,如下所示:

from pyjamas import Window
from pyjamas.ui import RootPanel, Button
from pyjamas.ui import HTML

def greet(sender):
    Window.alert("Hello!")

b = Button("Click me", greet)
RootPanel().add(b)

我运行以下命令:

^{pr2}$

它看起来运行正常,下面是我的结果目录:

Michael-Natkins-MacBook-Pro-2:HelloPyjs michaelnatkin$ ls .
hi.js   hi.py   output
Michael-Natkins-MacBook-Pro-2:HelloPyjs michaelnatkin$ ls output
__init__.py         gchart.gif          hi.safari.cache.html
_pyjs.js            hi.html             history.html
bootstrap.js            hi.ie6.cache.html       tree_closed.gif
bootstrap_progress.js       hi.mozilla.cache.html       tree_open.gif
disclosurePanelClosed.png   hi.nocache.html         tree_white.gif
disclosurePanelClosed_rtl.png   hi.oldmoz.cache.html
disclosurePanelOpen.png     hi.opera.cache.html

然后我将浏览器指向其中一个html文件:file:///Users/michaelnatkin/HelloPyjs/output/你好.html在

我得到。。。空白页。我的js控制台中唯一的错误是:

Uncaught SecurityError: Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match. 

我想这并不奇怪,因为html文件显示:

<html>
<!-- auto-generated html - You should consider editing and adapting this
 to suit your requirements. No doctype used here to force quirks mode; see
 wiki for details: http://pyjs.org/wiki/csshellandhowtodealwithit/
-->
<head>

<title>hi (Pyjamas Auto-Generated HTML file)</title>
<meta name="pygwt:module" content="hi">
</head>
<body style="background-color:white">
<script type="text/javascript" src="bootstrap.js"></script>
<iframe id="__pygwt_historyFrame" style="display:none;"></iframe>
<script type="text/javascript" src="bootstrap.js"></script>
<iframe id="__pygwt_historyFrame" style="display:none;"></iframe>
</body>
</html>

所以。。我完全卡住了。有人能告诉我如何让这个坏小子生产出产品吗?我有一个更复杂的应用程序,我想创建,但如果我不能说“你好”,它将不会顺利进行。谢谢您!在


Tags: 文件frompyimportcachehtmljsscript
1条回答
网友
1楼 · 发布于 2024-05-15 15:01:18

你在Firefox里也试过吗?虽然Chrome没有显示任何内容,但是使用Firefox,我会收到一条错误消息,它来自于你导入RootPanel和Button的方式。您应该将单行替换为:

from pyjamas.ui.RootPanel import RootPanel
from pyjamas.ui.Button import Button

在那之后,你的纽扣会恰当地问候我。在

关于Chrome的问题,可以使用allowfileaccessfromfiles来启动它,或者运行一个本地的web服务器来显示你的页面。更多详细信息:https://github.com/pyjs/pyjs/wiki/googlechromeproblems

相关问题 更多 >