Reputation: 31
I created a program in python through Anaconda (Spyder, more exactly) and made an .exe out of it with pyinstaller. Simply put, when I run it through the anaconda prompt it works, but when I double click it, it simply waits for a few seconds and then closes, without doing anything.
The code:
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) is basically the entire program that needs to run when I press a certain button on the tkinter widget that appears at start. Even if I require an input for the program to close, it still closes automatically and no tkinter widget appears.
I am a beginner, so sorry if this issue is a simple one.
Upvotes: 3
Views: 569
Reputation: 208
When you're running it from cmd it starts the command prompt and then starts the program thru the command prompt, but when running the program itself (by for example: double-clicking it), the window will close when it's done.
If you want to change this you can do that by putting this in you're script (on the last line):
input()
This will make sure the program doesn't get automatically closed as its waiting for input from a user.
Upvotes: 0
Reputation: 26
When you are double clicking it, the program is still being run, it's just that the window is closing as soon as it is finished so it doesn't look like it.
When you run from cmd you are able to see any output easily as the window won't close afterwards.
But the program will be getting run in both scenarios.
Upvotes: 1