gui2exe

简介wxPython wxPython是Python编程语言的一个GUI工具箱。他使得Python程序员能够轻松的创建具有健壮、功能强大的图形用户界面的程序。它是Python语言对流行的wxWidgets跨平台GUI工具库的绑定。而wxWidgets是用C++语言写成的。 和Python语言与wxWidgets GUI工具库一样,wxPython是开源软件。这意味着任何人都可以免费地使用它并且可以查看和修改它的源代码,或者贡献补丁,增加功能。   wxPython是跨平台的。这意味着同一个程序可以不经修改地在多种平台上运行。现今支持的平台有:32位微软Windows操作系统、大多数Unix或类Unix系统、苹果Mac OS X。  由于使用Python作为编程语言,wxPython编写简单、易于理解。

第一步下载gui2exe,wxpython,python2.7,py2exe

第二步安装gui2exe,直接双击GUI2Exe.py打开界面如下:

2010082308462148.png

第三步:找到根据

We will build the sample file that comes with py2exe, on: /site-packages/py2exe/sample/singlefile/gui/test_wx.py

With the GUI opened, hit Ctrl+N or choose File => New project... ;

Enter a name for the new project, i.e. "pyexe sample file";

In the central window that appears, under the Target Class box, right click on the list control and select "Add item(s)";

 Left click on the new item in Exe Kind column and select "windows";

 Left click on the new item in the Python Main Script column and browse to search for the aforementioned file;

On the Optimize, Compressed and Bundle Files drop down choices, choose 2, 2, 1 respectively;

Scroll down the central window to the bottom and check the XP Manifest File option;

Click on the Compile button. And you're done.

 You can follow the compilation steps in the bottom log window as py2exe builds your executable. 就可以转化成exe了。

import sys import wx sys.path.append('c:/Program Files/Microsoft Visual Studio 9.0/VC/redist/x86/Microsoft.VC90.CRT') //增加这一行 # By default the executables created by py2exe write output to stderr # into a logfile and display a messagebox at program end when there # has been any output. This logger silently overrides the default # behaviour by silently swallowing everything. if hasattr(sys, "frozen"): class logger: def write(self, text): pass # silently ignore everything sys.stdout = sys.stderr = logger() class MyFrame(wx.Frame): def __init__(self, parent, ID, title, pos=wx.DefaultPosition, size=(200, 200), style=wx.DEFAULT_FRAME_STYLE): wx.Frame.__init__(self, parent, ID, title, pos, size, style) panel = wx.Panel(self, -1) button = wx.Button(panel, 1003, "Close Me") button.SetPosition(wx.Point(15, 15)) wx.EVT_BUTTON(self, 1003, self.OnCloseMe) wx.EVT_CLOSE(self, self.OnCloseWindow) button = wx.Button(panel, 1004, "Press Me") button.SetPosition(wx.Point(15, 45)) wx.EVT_BUTTON(self, 1004, self.OnPressMe) def OnCloseMe(self, event): self.Close(True) def OnPressMe(self, event): # This raises an exception x = 1 / 0 def OnCloseWindow(self, event): self.Destroy() class MyApp(wx.App): def OnInit(self): frame = MyFrame(None, -1, "Hello from wxPython") frame.Show(True) self.SetTopWindow(frame) return True if __name__ == "__main__": app = MyApp(0) app.MainLoop()

转载于:https://www.cnblogs.com/caidaodaxia/archive/2010/08/23/1806123.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值