编译的pyinstaller独立文件给出了执行脚本界面消息失败。该怎么办?

时间:2019-11-05 15:00:13

标签: python tkinter pyinstaller

我使用pyinstaller创建了一个独立文件,当我尝试运行已编译的程序时,该文件未运行,而是给了我一个“无法执行脚本界面消息”

这是我的代码:

from tkinter import *
import mbl_db

def select_row(event):
    try:
        global selected
        index = content_list.curselection()[0]
        selected = content_list.get(index)
        tit_entry.delete(0, END)
        tit_entry.insert(END, selected[1])
        auth_entry.delete(0,END)
        auth_entry.insert(END, selected[2])
        year_entry.delete(0, END)
        year_entry.insert(END, selected[3])
        isbn_entry.delete(0, END)
        isbn_entry.insert(END, selected[4])
    except IndexError:
        pass

def view_command():
    content_list.delete(0, END)
    for data in mbl_db.view():
        content_list.insert(END, data)

def search_command():
    content_list.delete(0, END)
    for data in mbl_db.search(tit_text.get(), auth_text.get(), year_text.get(), isbn_text.get()):
        content_list.insert(END, data)

def add_command():
    mbl_db.add(tit_text.get(), auth_text.get(), year_text.get(), isbn_text.get())
    content_list.delete(0, END)
    content_list.insert(END, (tit_text.get(), auth_text.get(), year_text.get(), isbn_text.get()))

def delete_command():
    mbl_db.delete(selected[0])

def update_command():
    mbl_db.update(selected[0], tit_text.get(), auth_text.get(), year_text.get(), isbn_text.get())

# The main app window
app_interface = Tk()
app_interface.title("My Books List")
app_interface.iconbitmap("icon.ani")

# The app's label widgets
tit_label = Label(app_interface, text="Title")
tit_label.grid(row=0, column=0)

auth_label = Label(app_interface, text="Author")
auth_label.grid(row=0, column=2)

year_label = Label(app_interface, text="Year")
year_label.grid(row=1, column=0)

isbn_label = Label(app_interface, text="ISBN")
isbn_label.grid(row=1, column=2)

# The app's entry widgets
tit_text = StringVar()
tit_entry = Entry(app_interface, textvariable=tit_text)
tit_entry.grid(row=0, column=1)

auth_text = StringVar()
auth_entry = Entry(app_interface, textvariable=auth_text)
auth_entry.grid(row=0, column=3)

year_text = StringVar()
year_entry = Entry(app_interface, textvariable=year_text)
year_entry.grid(row=1, column=1)

isbn_text = StringVar()
isbn_entry = Entry(app_interface, textvariable=isbn_text)
isbn_entry.grid(row=1, column=3)

# The content list and scrollbar
content_list = Listbox(app_interface, height=6, width=35)
content_list.grid(row=2, column=0, columnspan=2, rowspan=6)

scr_bar = Scrollbar(app_interface)
scr_bar.grid(row=2, column=2, rowspan=6)

content_list.configure(yscrollcommand=scr_bar.set)
scr_bar.configure(command=content_list.yview)

content_list.bind('<<ListboxSelect>>', select_row)

# The buttons
view_all_btn = Button(app_interface, text="View All", width=12, command=view_command)
view_all_btn.grid(row=2, column=3)

search_btn = Button(app_interface, text="Search", width=12, command=search_command)
search_btn.grid(row=3, column=3)

add_btn = Button(app_interface, text="Add", width=12, command=add_command)
add_btn.grid(row=4, column=3)

update_btn = Button(app_interface, text="Update", width=12, command=update_command)
update_btn.grid(row=5, column=3)

del_btn = Button(app_interface, text="Delete", width=12, command=delete_command)
del_btn.grid(row=6, column=3)

close_btn = Button(app_interface, text="Close", width=12, command=app_interface.destroy)
close_btn.grid(row=7, column=3)

app_interface.mainloop()

我导入的mbl_db脚本上的代码如下:

import sqlite3

def create():
    mbl_conn = sqlite3.connect("mbl.db")
    mbl_cur = mbl_conn.cursor()
    mbl_cur.execute("CREATE TABLE IF NOT EXISTS books(id INTEGER PRIMARY KEY, title TEXT, author TEXT, year INTEGER, isbn TEXT)")
    mbl_conn.commit()
    mbl_conn.close()

def add(title, author, year, isbn):
    mbl_conn = sqlite3.connect("mbl.db")
    mbl_cur = mbl_conn.cursor()
    mbl_cur.execute("INSERT INTO books VALUES(NULL,?,?,?,?)",(title, author, year, isbn))
    mbl_conn.commit()
    mbl_conn.close()

def view():
    mbl_conn = sqlite3.connect("mbl.db")
    mbl_cur = mbl_conn.cursor()
    mbl_cur.execute("SELECT * FROM books")
    data = mbl_cur.fetchall()
    mbl_conn.close()
    return data

def search(title="", author="", year="", isbn=""):
    mbl_conn = sqlite3.connect("mbl.db")
    mbl_cur = mbl_conn.cursor()
    mbl_cur.execute("SELECT * FROM books WHERE title=? OR author=? OR year=? OR isbn=?", (title, author, year, isbn))
    data = mbl_cur.fetchall()
    mbl_conn.close()
    return data

def delete(id):
    mbl_conn = sqlite3.connect("mbl.db")
    mbl_cur = mbl_conn.cursor()
    mbl_cur.execute("DELETE FROM books WHERE id=?", (id,))
    mbl_conn.commit()
    mbl_conn.close()

def update(id, title, author, year, isbn):
    mbl_conn = sqlite3.connect("mbl.db")
    mbl_cur = mbl_conn.cursor()
    mbl_cur.execute("UPDATE books SET title=?, author=?, year=?, isbn=? WHERE id=?", (title, author, year, isbn, id))
    mbl_conn.commit()
    mbl_conn.close()

create()

我还从https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz安装了pyinstaller,因为由于安装了pyinstaller软件包,我之前遇到了问题。

如何解决此错误消息?

0 个答案:

没有答案