我使用python 3.1.1,我一直在尝试编译我今天早些时候编写的程序,我认为代码很短,可以在下面发布。
from tkinter import *
class Application(Frame):
""" GUI application that creates a story based on user input. """
def __init__(self, master):
""" Initialize Frame. """
super(Application, self).__init__(master)
self.grid()
self.label1()
self.label2()
def label1(self):
Label(self,
text = "Shop Keeper 1.1",
font = ("fixedsys",
72)).grid(row = 0, column = 0, sticky = W)
def label2(self):
Label(self,
text = "Welcome to Shop Keeper 1.1!"
).grid(row = 1, column = 0, sticky = W)
# create a label and text entry for a plural noun
Label(self,
text = "Block name:"
).grid(row = 2, column = 0, sticky = W)
self.BlokID = Entry(self)
self.BlokID.grid(row = 2, column = 1, sticky = W)
# create a label and text entry for a verb
Label(self,
text = "Amount:"
).grid(row = 3, column = 0, sticky = W)
self.Amound = Entry(self)
self.Amound.grid(row = 3, column = 1, sticky = W)
Label(self,
text = "Name:"
).grid(row = 4, column = 0, sticky = W)
self.nama = Entry(self)
self.nama.grid(row = 4, column = 1, sticky = W)
Label(self,
text = "Desired price:"
).grid(row = 5, column = 0, sticky = W)
self.desprice = Entry(self)
self.desprice.grid(row = 5, column = 1, sticky = W)
# create a submit button
Button(self,
text = "Submit order",
command = self.submit
).grid(row = 6, column = 1, sticky = W)
self.submit = Text(self, width = 75, height = 10, wrap = WORD)
self.submit.grid(row = 7, column = 0, columnspan = 4)
def submit(self):
""" Fill text box with new story based on user input. """
# get values from the GUI
BlockID = self.BlokID.get()
amount = self.Amound.get()
name = self.nama.get()
price = self.desprice.get()
emess = name
emess += " ordered "
emess += amount
emess += " units of "
emess += BlockID
emess += " at the price of "
emess += price
emess += " each."
emess += "\n"
# display the story
self.submit.insert(0.0, emess)
# main
root = Tk()
root.title("Shop Keeper 1.0")
app = Application(root)
root.mainloop()
我一直试图用cx_freeze编译它几个小时,没有运气。它创建了文件夹,但是当我点击.exe时它会打开并快速关闭。多次点击非常快,我发现它缺少一些与Tkinter有关的模块,在搜索论坛后,我得出的结论是它缺少模块。但是,我无法解决它!我已经尝试按照建议添加tcl8.5和tk8.5文件夹,但它似乎没有解决它。我尽我所能,所以我把这个问题作为最后的手段来创造。创建的文件夹包含以下文件:
_socket.pyd
_tkinter.pyd
library.zip
mad_lib.exe
python31.dll
select.pyd
tcl85.dll
tk85.dll
unicodedata.pyd
请帮忙!
答案 0 :(得分:0)
我尝试了以下内容,它对我来说很好。
使用activestate python 3.2.2.3(http://www.activestate.com/activepython/downloads)
然后我去了http://cx-freeze.sourceforge.net/并下载了&安装了MSI for Python 3.2(我使用的是64位)。
我将您的程序保存为C:\ Scripts \ Shopkeeper.py
接下来我跑了这个:
C:\Python32\Scripts\cxfreeze C:\Scripts\Shopkeeper.py --target-dir C:\cxfreezetest
然后我跑了C:\cxfreezetest\Shopkeeper.exe
,它运行良好。