我使用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
请帮忙!