tkinter和CX_Freeze:不起作用

时间:2018-02-11 15:11:10

标签: python tkinter cx-freeze

我是python的初学者,使用互联网上的开源代码编写代码来练习。我编写了一个代码,用于从特定站点获取信息并将信息保存在excel中。当我测试时代码运行完美但是当我使用CX_Freeze创建exe时它不起作用。附件是我打开exe时得到的错误的快照。

以下是我的脚本:Scorecard1和setup

import bs4 as bs
import urllib.request
import numpy as np
import numpy.core._methods
import numpy.lib.format
import pandas as pd
import csv
import os
import xlsxwriter
from tkinter import *

import os, os.path
# Take the tcl/tk library from local subdirectory if available.
if os.path.isdir('libtcltk84'):
    os.environ['TCL_LIBRARY'] = 'libtcltk84\\tcl8.4'
    os.environ['TK_LIBRARY'] =  'libtcltk84\\tk8.4'

def do_it():
    sauce = urllib.request.urlopen(str(scorecard.get())).read()
    soup = bs.BeautifulSoup(sauce,'lxml')
    #Batsmen Name
    a = []
    for div in soup.find_all('div',class_='cell batsmen'):
        a.append(div.text.strip())

    b = []
    for div in soup.find_all('div',class_='cell commentary'):
        b.append(div.text.strip())

    #Batsmen Stats
    myfile = open('C:/apps/temp.csv','w',newline= '')
    writer = csv.writer(myfile)
    for div in soup.find_all('div',class_='cell runs'):
        writer.writerow([div.text])
    myfile.close()

    y=[]
    with open('C:/apps/temp.csv','r') as csv_file:
        for x in range(150):
            y.append(csv_file.readline().strip())
        Runs = (y[0:150:5])
        Balls = (y[1:150:5])
        Fours = (y[2:150:5])
        Sixes = (y[3:150:5])
        Strike = (y[4:150:5])
    A = np.array(a)
    B = np.array(b)
    C = np.array(Runs)
    D = np.array(Balls)
    E = np.array(Fours)
    F = np.array(Sixes)
    G = np.array(Strike)
    df1 = pd.DataFrame(A)
    df2 = pd.DataFrame(B)
    df3 = pd.DataFrame(C)
    df4 = pd.DataFrame(D)
    df5 = pd.DataFrame(E)
    df6 = pd.DataFrame(F)
    df7 = pd.DataFrame(G)
    df = pd.concat([df1,df2,df3,df4,df5,df6,df7],axis=1)
    writer = pd.ExcelWriter("C:/apps/Scorecard.xlsx", engine="xlsxwriter")
    df.to_excel(writer, startrow=2)

    website = str(scorecard.get())
    datalist = pd.read_html(website)
    df8 = pd.DataFrame(datalist[0])
    df9 = pd.DataFrame(datalist[1])
    df8.to_excel(writer, startrow=35)
    df9.to_excel(writer, startrow=49)
    writer.save()
    os.remove('C:/apps/temp.csv')

root = Tk()
root.title("T20 Score Update")
root.geometry("640x140+0+0")

heading = Label(root, text='Apna T20 League').pack()
Label1 = Label(root, text='Paste Link Here: ').pack()

scorecard = StringVar()
input_box = Entry(root, textvariable=scorecard, width=50).pack()

click = Button(root, text='Submit', command=do_it).pack()
root.mainloop()

=======

setup.py

import sys
from cx_Freeze import setup, Executable
import os.path
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')

additional_mods = ['numpy.core._methods', 'numpy.lib.format']

build_exe_options = {"includes": ["tkinter","additional_mods","urllib","csv","xlsxwriter","bs4","pandas"]}

base = None
if sys.platform == "Win32":
    base = "Win32GUI"

options = {
    'build_exe': {
        'include_files':[
            os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
            os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
         ],
    },
}

setup(
    name="Scorecard",
    version="0.1",
    description="Sample cx_Freeze Tkinter script",
    options={"build.exe":build_exe_options},
    executables=[Executable("Scorecard1.py", base=base)])

Error Msg

请参阅以上链接获取exe错误消息。谢谢

0 个答案:

没有答案