简体   繁体   中英

What do I need to do for adding python executable to HTML?

我使用乌龟图形在python中制作了自己的游戏,我想将其转换为可在HTML中运行的可执行文件,我是否应该了解其他信息?

Edit: An executable is not likely what you're looking for per Chris' answer . He also provides info about making an installer, if you do want to accomplish that. My answer addresses getting your Python game running in the browser.

When I initially saw this question, I thought it wasn't a thing. However, Python is just a language. Anything can interpret and run Python logic. It's just a matter if someone has built something that works in the browser and interprets Python.

After some Google searching, I found Skulpt: http://www.skulpt.org/ . It appears to be a Javascript implementation of a Python interpreter. This is important because browsers only understand Javascript, not Python.

Something worth noting is that Skulpt appears to only have partial support for Python 3. It mostly focuses on Python 2. This could be a major concern because Python 2 is scheduled for end of life January 1st, 2020 (at least, that's what pip told me).

There are examples of using Skulpt on its page. Heads up that you'll likely need to learn some amount of Javascript, but if you're comfortable with Python already, that shouldn't be terrible.

Edit: There also appears to be Brython: https://brython.info/ . This is a Python 3-focused implementation. At first glance, it looks a little easier to use, too.

Hope this helps!

Please know that executables (.exe) & browsers tend not to work together. See this stackoverflow question referring to .exe's & html The long & short of it is that you can setup .exe's so they can be downloaded, but not rendered in the browser.

If you want to convert your script to a .exe file, you'll need something like pyinstaller . Here's a link to some info about installing & using it.

TheBeege's answer is on point with rendering in the browser with python when you already have code written with turtle . I just wanted to make sure anyone coming here looking for info on python with executables could find it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM