Chinaunix

标题: 初学python,做了个井字棋游戏 [打印本页]

作者: kavingray    时间: 2009-02-21 20:02
标题: 初学python,做了个井字棋游戏


看了一点wxpython,同时想实践下python的运用,就做了这个井字棋游戏。

可以两人游戏和人机对战。。因为当作练习,所以也顺便做了保存游戏悔棋等很无聊的功能~

用的是python2.5 + wxpython2.8,最后用py2exe打包了下

源码和打包的exe文件在附件,呵呵,详细介绍的话到 这里

SimpleTicTacToe.rar

4.3 MB, 下载次数: 590


作者: zhenglxd    时间: 2009-02-21 21:59
good!支持!不过发的不是时候啊 双休日发没什么人上论坛的
作者: phpcool    时间: 2009-02-21 23:24
不错~~~
作者: bleem1998    时间: 2009-02-22 01:49
我比较感兴趣LZ的py2exe是怎么打成这样的包的
请问怎样把程序打成一个很大的执行文件的?
我用pybuilder打的包特别大
而且文件特别多
不像LZ的是一个单独的执行文件很酷
作者: kavingray    时间: 2009-02-22 10:03
这是我py2exe打包时setup.py里的代码




  1. from distutils.core import setup
  2. import py2exe
  3. import sys

  4. # If run without args, build executables, in quiet mode.

  5. if len(sys.argv) == 1:
  6.     sys.argv.append("py2exe")
  7.     sys.argv.append("-q")

  8. class Target:
  9.     def __init__(self, **kw):
  10.         self.__dict__.update(kw)
  11.         # for the versioninfo resources
  12.         self.company_name = "www.kavingray.com"
  13.         self.copyright = "Kavin 2008"
  14.         self.name = "Simple Tic Tac Toe"

  15. ################################################################

  16. # A program using wxPython
  17. # The manifest will be inserted as resource into iTip.exe.  This
  18. # gives the controls the Windows XP appearance (if run on XP ;-)
  19. #
  20. # Another option would be to store it in a file named
  21. # iTip.exe.manifest, and copy it with the data_files option into
  22. # the dist-dir.
  23. #
  24. manifest_template = """
  25. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  26. <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  27. <assemblyIdentity
  28.     version="5.0.0.0"
  29.     processorArchitecture="x86"
  30.     name="%(prog)s"
  31.     type="win32"
  32. />
  33. <description>%(prog)s Program</description>
  34. <dependency>
  35.     <dependentAssembly>
  36.         <assemblyIdentity
  37.             type="win32"
  38.             name="Microsoft.Windows.Common-Controls"
  39.             version="6.0.0.0"
  40.             processorArchitecture="X86"
  41.             publicKeyToken="6595b64144ccf1df"
  42.             language="*"
  43.         />
  44.     </dependentAssembly>
  45. </dependency>
  46. </assembly>

  47. """

  48. ################################################################

  49. RT_MANIFEST = 24

  50. Sttt = Target(
  51.     # used for the versioninfo resource
  52.     description = "A Funny Game",
  53.     # what to build
  54.     script = "SimpleTicTacToe.py",

  55.     other_resources = [(RT_MANIFEST, 1, manifest_template % dict(prog="Simple Tic Tac Toe"))],
  56.     icon_resources = [(1, "edit.ico")],
  57.     dest_base = "Simple Tic Tac Toe")


  58. setup(
  59.     options = {"py2exe": {"compressed": 1,
  60.                           "optimize": 2,
  61.                           "ascii": 1,
  62.                           "bundle_files": 1}},
  63.     zipfile = None,
  64.     windows = [Sttt],
  65.     )


复制代码




中间那段manifest_template是解决打包后XP或Vista下窗体风格样式丢失的问题,最底下的zipfile = None就是不生成library.zip等很多压缩文件,上面代码打包就能生成单个exe那样了

[ 本帖最后由 kavingray 于 2009-2-22 10:04 编辑 ]
作者: bleem1998    时间: 2009-02-22 18:21
谢谢
发现个问题
关闭程序后进程依然存在
作者: kavingray    时间: 2009-02-22 21:58
嗯,发现了~怎么会这样,难道非得加上sys.exit()?




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2