1

我使用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

请帮忙!

4

1 回答 1

0

我尝试了以下方法,对我来说效果很好。

使用 activestate python 3.2.2.3 ( http://www.activestate.com/activepython/downloads )

然后我去了http://cx-freeze.sourceforge.net/并下载并安装了适用于 Python 3.2 的 MSI(我使用的是 64 位)。

我将您的程序保存为 C:\Scripts\Shopkeeper.py

接下来我运行了这个:

C:\Python32\Scripts\cxfreeze C:\Scripts\Shopkeeper.py --target-dir C:\cxfreezetest

然后我跑了C:\cxfreezetest\Shopkeeper.exe,效果很好。

在此处输入图像描述

于 2013-04-06T05:03:56.347 回答