Tkinter 项目可下载 [英] Tkinter Project downloadable

查看:31
本文介绍了Tkinter 项目可下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用python和tkinter制作了这个小项目,但我只是想知道有没有办法让它成为一个可安装的应用程序供人们使用?还是我想为此使用不同的程序?我确实尝试查找它,但找不到任何内容.如果有人能帮助我,我将不胜感激!!

I made this small project for practice with python and tkinter but I was just wondering is there a way to make it an installable application for people to use it? or am I suppose to use a different program for that? I did try looking it up and couldn't find anything on it. If anyone could help me out I would be so thankful!!

推荐答案

有很多方法可以做到这一点:py2exe、PyInstaller、CXFreeze...这是使用 py2exe 的方法.

There are many ways to do this: py2exe, PyInstaller, CXFreeze... Here is how to do it with py2exe.

  1. 以管理员身份在 CMD 中使用 pip install py2exe 为您的系统下载并安装正确版本的 py2exe,或从 这里.
  2. 在与您的代码相同的目录中创建一个python脚本;约定是将其称为 setup.py.
  3. 在脚本中,粘贴以下代码:

  1. Download and install the correct version of py2exe for your system using pip install py2exe in CMD as Administrator or download and install it manually from here.
  2. Create a python script in the same directory as your code; the convention is to call it setup.py.
  3. In the script, paste the following code:

from distutils.core import setup
import py2exe
setup(console = ["you_filename_here.py"], 

(记得将 your_filename_here.py 替换为你项目的主 python 文件)

(remember to replace your_filename_here.py with your project's main python file)

打开另一个 CMD 窗口,将目录更改为您的项目所在的位置(例如 cd C:\Projects\TestProject),键入以下内容,然后按 Enter.

Open another CMD window, change directory to where your project is (e.g. cd C:\Projects\TestProject), type the following, and press enter.

python setup.py py2exe

这将创建大量输出 - 不用担心 - 并将创建一个名为 dist 的目录,其中包含在任何计算机上运行该程序所需的所有文件,而无需安装Python.由于 tkinter 是默认的 Python 模块,因此您不需要做任何额外的工作.但是,如果您将来将它与其他模块一起使用,您可能需要做一些额外的调整才能使其工作(只需 google 即可!)

This will create a lot of output - don't worry about that - and will create a directory called dist which contains all the files you need to run the program on any computer without needing to install Python. Since tkinter is a default python module, you should not need to do any additional work. However, if you use this in future with other modules, you may need to do some extra fiddling to get it to work (just google it!)

有很多方法可以创建 .msi 文件(即安装程序),例如 Inno Setup.

There are many ways to create .msi files (i.e. installers) such as Inno Setup.

这篇关于Tkinter 项目可下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆