user interface - Terminating an exe built from a GUI in python from Background Processes -


i created simple gui in python 3.4 using tkinter 8.5. used cx_freeze build exe gui. when run exe, notice program still shows under 'background processes' in task manager after terminate using quit button or using close button in window.

the gui works this: select file type drop down list, read file using command button , save separate file. problem happens if close gui after using it. if open gui , close using quit button or close button, not stay background process.

is normal behave this? if not can terminate properly?

the simplified code gui given below. function 'fileselect' calls functions module 'dataselect'. if needed, provide code 'dataselect' module also.

from dataselect import * openpyxl import workbook tkinter import * tkinter import ttk, filedialog  root = tk() root.title("select data file")  # actual file selection based on combobox selection def fileselect():     file_type = filetype.get()     if file_type == ".txt":         text = selecttxt()         textfile = filedialog.asksaveasfile(mode='w', defaultextension=".txt")         line in text:             number in line:                 textfile.write(str(number)+" ")             textfile.write('\n')     elif file_type == ".xlsx":         excel = selectxlsx()         excelfile = filedialog.asksaveasfile(mode='w', defaultextension=".xlsx")         excelfilename = excelfile.name         excelbook = workbook()         excelsheet = excelbook.active         rows = 0         excel_row in excel:             cols = 0             excel_cell in excel_row:                 excelsheet.cell(row=rows, column=cols).value = excel[rows][cols]                 cols += 1             rows += 1         excelbook.save(excelfilename)  def quit():     global root     root.destroy()  # select file type opened (.txt or .xlsx now) ttk.label(root, text="please select file type").grid(column=2, row=1) filetype = stringvar() sel_type = ttk.combobox(root,values=('.txt','.xlsx'),textvariable=filetype) sel_type.grid(column=2,row=2,sticky=e)  # command button opening file cb_open = ttk.button(root, text="select file", command=fileselect) cb_open.grid(column=2, row=3)  # command button quitting gui cb_quit = ttk.button(root, text="quit", command=quit) cb_quit.grid(column=1, row=3)  root.mainloop() 

there 2 things need change: 1) add sys.exit() quit method

    def quit():         root.quit         root.destroy         sys.exit() 

2) add protocol root

    root.protocol("wm_delete_window", quit) 

finally, don't forget import sys.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -