Tkinter代码可以从spyder正常运行,但是转换为.exc时无法打开python

问题描述

我有一些代码旨在获取数据文件文件夹的路径,提取并整理数据,然后返回可以保存的单个pandas数据框。为了使其更加用户友好,我在tkinter中添加了一个用户界面。一切在spyder中都可以正常运行,并且使pyinstaller可执行文件运行正常,但是当我尝试运行.exc时,它只是打开空白命令窗口而不打开UI。它不会给出任何错误,所以我不知道从哪里开始调试,不胜感激地收到了任何帮助。

我的代码包含四个文件:

tidyEPR.py (打开并清除单个epr文件的单个函数。软件包: Pandas

rowNames.csv (包含变量名。)

combEPRs.py (单个函数,它遍历数据文件并调用tidyEPR()将数据合并到单个数据框中,并打开rowNames.csv重命名行。软件包: Pandas ,pathlib,glob

practice.py (一个tkinter应用程序,它允许用户输入数据并保存位置并按下按钮以运行,并调用combEPR。软件包: Tkinter,os,sys

要制作.exc文件,请将以上所有内容放入一个文件夹中,然后使用

pyinstaller --onefile Practice.py

pyinstaller Practice.py

在cmd中,在这两种情况下,它似乎都可以成功运行并制作.exc文件。

不会引发任何错误。我尝试使用上述方法转换其他tkinter脚本,并且效果很好,所以我的代码肯定有问题。

我以前从未尝试做这种事情,所以对不起,我的代码可能有点混乱。

这是Practice.py:

import tkinter as tk
import os
import sys
#import custom functions
from combEPRs import combEPRs


#set working directory to file location
os.chdir(os.path.dirname(sys.argv[0]))

window = tk.Tk()

#initilaise df
df="empty"

def makeFile():
    global df
    #retrive entered text
    enteredText = ent_dataPath.get()
    #create dataframe from data files in entred path
    df = combEPRs(enteredText)
    #update label to show the finished dataframe
    lbl_ConsoleReadout.config(text=df)

def saveFile():
    global df
    #change label to say "saving..."
    lbl_ConsoleReadout.config(text="saving...")
    #retrive entered text
    enteredText = ent_savePath.get()
    #save dataframe
    df.to_csv(enteredText)
    #change label text to say "Done!"
    lbl_ConsoleReadout.config(text="Done!")

frame = tk.Frame(borderwidth=5)
frame.pack()

#make label to explain what to do
lbl_info = tk.Label(
    text="Put full path to the data folder then press go,if you are hapy with output put in full save path and press save",master = frame,)
lbl_info.pack(pady=10)

#make text entry widget to get path to data folder
ent_dataPath = tk.Entry(
    master = frame,width = 100
)
ent_dataPath.pack(pady=10)

#make button to press to submit folder to combEPRs
btn_go = tk.Button(
    text="GO",width = 10,height = 2,command = makeFile
)
btn_go.pack(pady=10)

#make text widget to print output to.
lbl_ConsoleReadout = tk.Label(
    width = 100
)
lbl_ConsoleReadout.pack()

#make text entry widget to get path to to save to
ent_savePath = tk.Entry(
    master = frame,width = 100
)
ent_savePath.pack(pady=10)

#make save button
btn_save = tk.Button(
    text="SAVE",command = saveFile
)
btn_save.pack(pady=10)

window.mainloop()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)