【发布时间】:2021-12-24 09:03:46
【问题描述】:
我通过 Anaconda(更准确地说是 Spyder)在 python 中创建了一个程序,并使用 pyinstaller 制作了一个 .exe。简单地说,当我通过 anaconda 提示符运行它时,它可以工作,但是当我双击它时,它只是等待几秒钟然后关闭,什么都不做。
代码:
import xlrd
from scipy.fft import fft
import numpy as np
import tkinter as tk
def main():
root =tk.Tk()
root.title("Data input window")
canvas1 = tk.Canvas(root, width = 620, height = 210, relief = 'raised')
canvas1.pack()
inputdata = tk.StringVar(root)
def getvalue():
loc = inputdata.get()
run(loc)
label1 = tk.Label(root, text='Copy file and paste here:')
label1.config(font=('helvetica', 14))
canvas1.create_window(310, 25, window=label1)
e1 = tk.Entry(root,textvariable = inputdata, width=100,fg="blue",bd=3,selectbackground='violet')
canvas1.create_window(310, 65, window=e1)
label2 = tk.Label(root, text='Only .xls files supported')
label2.config(font=('helvetica', 8))
canvas1.create_window(310, 105, window=label2)
button1 = tk.Button(root, text='Input data', fg='White', bg= 'dark green', height = 1, width = 10,command=getvalue)
canvas1.create_window(310, 180, window=button1)
root.mainloop()
s = input('Press X to exit')
return 0;
if __name__ == '__main__':
main()
run(loc) 基本上是当我按下启动时出现的 tkinter 小部件上的某个按钮时需要运行的整个程序。即使我需要输入以关闭程序,它仍然会自动关闭并且不会出现 tkinter 小部件。
我是初学者,如果这个问题很简单,很抱歉。
【问题讨论】:
-
您可以尝试从命令提示符运行 exe 文件吗? (不是python文件)
-
你在main函数末尾写return语句是不小心还是故意用分号写的?
-
关于 ;退货后是的,这是不小心。如果这就是我的整个程序出现故障的原因,我会很生气哈哈。是的,我从命令提示符运行了 exe 文件,它工作得很好