我正在尝试创建一个包含4个活动按钮和4个字段的窗口。我正在使用Visual Basic 2017和Python包3.6。 由于某些原因,当我执行程序时,出现以下错误消息: “线程0x1已退出,代码为0(0x0)。 程序“ python.exe”已退出,代码为0(0x0)。” 我检查了代码,多余的制表符或空格中是否存在任何不一致之处,但未找到任何内容。 有人知道该如何应对吗?我正在执行的代码如下:
from tkinter import *
import sys
#define the labels of the fileds
fields = 'Reference', 'CL', 'INV', 'Date1', 'Date2'
#define how the fields work
def fetch(entries):
for entry in entries:
field = entry[0]
text = entry[1].get()
print('%s: "%s"' % (field, text))
def makeform(root, fields):
entries = []
for field in fields:
row = Frame(root)
lab = Label(row, width=15, text=field, anchor='w')
ent = Entry(row)
row.pack(side=TOP, fill=X, padx=5, pady=5)
lab.pack(side=LEFT)
ent.pack(side=RIGHT, expand=YES, fill=X)
entries.append((field, ent))
return entries
def quit(root):
root.destroy()
sys.exit()
def save_file():
file_name = filedialog.asksaveasfilename(initialdir = __file__,title = "Select file")
#insert function to save the file as file_name
print(file_name)
def open_file():
open_file = tkFileDialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("csv files","*.csv"),("all files","*.*")))
print (open_file)
if __name__ == '__main__':
root = Tk()
ents = makeform(root, fields)
root.bind('<Return>', (lambda event, e=ents: fetch(e)))
#button 1 - not set to open
b1 = button (root, text='Open',command=lambda: open_file())
b1.pack(side=LEFT, padx=5, pady=5)
b2 = Button(root, text='Run', command=(lambda e=ents: fetch(e)))
b2.pack(side=LEFT, padx=5, pady=5)
#button 2 - dies not function accordingly
b3 = Button(root, text='Save', command=lambda: save_file())
b3.pack(side=LEFT, padx=5, pady=5)
b4 = Button(root, text='Quit', command=lambda: quit(root))
b4.pack(side=LEFT, padx=5, pady=5)
root.mainloop()
谢谢!