Python Forum
Python script on windows 10 shuts down
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python script on windows 10 shuts down
#1
My python script runs on Windows 10. It uses various libraries including tkinter.
Opening it in idle, it runs perfectly.
I right click on the script and associate it with python. When I double click the script it opens as a tkinter window with buttons, then a file manager opens as programmed, and I select a file, but the script then closes.
When I open the script in idle, the program continues to work when the file is selected.
I have tried both as a .py and a .pyw. This makes no difference
I include an example below. I omitted some of the def's to see if one of them was the problem, but that was not the case.
It crashes even at this.
Can anyone suggest what is happening ?

import matplotlib.pyplot as plt 
import pandas as pd
import xlrd
import openpyxl
import os
import numpy as np
from tkinter import *
from tkinter import messagebox

root=Tk()
root.title("Tam Pepper Programming")
# size of window
root.geometry('350x150')
#Centre the Window
root.eval('tk::PlaceWindow . center')

    
def GetFile():
    from tkinter import filedialog 
    filename = filedialog.askopenfilename(initialdir = "/home/pi/Pi4_Lan/WeatherData/", 
                                          title = "Select a File", 
                                          filetypes = (("Excel files", 
                                                        "*.xlsx*"), 
                                                       ("all files", 
                                                        "*.*"))) 
    global pathTo
    pathTo=str(filename)
    print(pathTo)
    global df
    df=pd.read_excel(pathTo, 'Sheet1' )


def Last8():
    print("Last8")

def Last24():
    print("Last24")

def Last72():
    print("Last72")



def But1():
    Last8()
def But2():  
    Last24()
def But3():  
    Last72()

#QUIT program
def close_window(): 
    root.destroy()



#Place the Buttons
b1=Button(text="Last 8 readings",command=But1)#react to button press
b1.place(x=30,y=10)#Position button

b2=Button(text="Last 24 hrs",command=But2)#react to button press
b2.place(x=150,y=10)#Position button

b3=Button(text="Last 72 Hrs",command=But3)#react to button press
b3.place(x=250,y=10)#Position button

#QUIT BUTTON
bQuit=Button(text="Quit",command=close_window)
bQuit.place(x=160,y=100)

GetFile()

root.mainloop
Reply
#2
(Mar-07-2021, 08:55 AM)TamP Wrote: My python script runs on Windows 10. It uses various libraries including tkinter.
Opening it in idle, it runs perfectly.
I right click on the script and associate it with python. When I double click the script it opens as a tkinter window with buttons, then a file manager opens as programmed, and I select a file, but the script then closes.
When I open the script in idle, the program continues to work when the file is selected.
I have tried both as a .py and a .pyw. This makes no difference
I include an example below. I omitted some of the def's to see if one of them was the problem, but that was not the case.
It crashes even at this.
Can anyone suggest what is happening ?

import matplotlib.pyplot as plt 
import pandas as pd
import xlrd
import openpyxl
import os
import numpy as np
from tkinter import *
from tkinter import messagebox

root=Tk()
root.title("Tam Pepper Programming")
# size of window
root.geometry('350x150')
#Centre the Window
root.eval('tk::PlaceWindow . center')

    
def GetFile():
    from tkinter import filedialog 
    filename = filedialog.askopenfilename(initialdir = "/home/pi/Pi4_Lan/WeatherData/", 
                                          title = "Select a File", 
                                          filetypes = (("Excel files", 
                                                        "*.xlsx*"), 
                                                       ("all files", 
                                                        "*.*"))) 
    global pathTo
    pathTo=str(filename)
    print(pathTo)
    global df
    df=pd.read_excel(pathTo, 'Sheet1' )


def Last8():
    print("Last8")

def Last24():
    print("Last24")

def Last72():
    print("Last72")



def But1():
    Last8()
def But2():  
    Last24()
def But3():  
    Last72()

#QUIT program
def close_window(): 
    root.destroy()



#Place the Buttons
b1=Button(text="Last 8 readings",command=But1)#react to button press
b1.place(x=30,y=10)#Position button

b2=Button(text="Last 24 hrs",command=But2)#react to button press
b2.place(x=150,y=10)#Position button

b3=Button(text="Last 72 Hrs",command=But3)#react to button press
b3.place(x=250,y=10)#Position button

#QUIT BUTTON
bQuit=Button(text="Quit",command=close_window)
bQuit.place(x=160,y=100)

GetFile()

root.mainloop
Reply
#3
Solved
I had root.mainloop at the end instead of root.mainloop()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Triggering a ps1 script in remote windows server via http python request jasveerjassi 1 365 Jan-26-2024, 07:02 PM
Last Post: deanhystad
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,186 Jun-29-2023, 11:57 AM
Last Post: gologica
  Python script running under windows over nssm.exe JaroslavZ 0 704 May-12-2023, 09:22 AM
Last Post: JaroslavZ
  How to compile a Python script for a Windows / Linux executable? netanelst 2 1,316 May-24-2022, 07:02 AM
Last Post: netanelst
  Setup Portable Python on Windows for script starts with double clicks? pstein 0 1,811 Feb-18-2022, 01:29 PM
Last Post: pstein
  How to kill a bash script running as root from a python script? jc_lafleur 4 5,877 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 2,291 May-28-2020, 05:27 PM
Last Post: micseydel
  Running this script on Windows? Winfried 2 2,305 May-15-2020, 01:39 PM
Last Post: Winfried
  script works in windows but not in linux ovidius80 2 2,734 Apr-29-2020, 02:10 PM
Last Post: ovidius80
  Help for Windows service recycling script Rajesh_K 1 1,817 Apr-22-2020, 06:07 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020