Title: it opens a directory after closing
Tags: python;tkinter;debug-information
Question: I code this program using python.... it works fine, but when I run the program and does not do anything or like running and closing it ,,, it displays the directory it is saved on.
any help to solve this ???????
Code starts here&gt;&gt;
#1 import all the libraries
import os
import tkinter.filedialog as fd
import tkinter.messagebox as mb
from tkinter import *
#2 Defining the functions -&gt;&gt;&gt;&gt; four Function
def open_file(): #a function for opening file
file = fd.askopenfilename(title='choose a file to open',filetypes=[('All files','*.*')])
os.startfile(file)
def open_folder():
foldertodlt = fd.askdirectory(title='Select a folder to Open')
os.startfile(foldertodlt)
def delete_file():
filetodlt = fd.askopenfilename(title='Select a File to Delete! ',filetypes=[('All files','*.*')])
os.remove(filetodlt)
mb.showinfo(title='Deleting File', message='File Deleted! ')
def delete_folder():
fodlertodlt = fd.askdirectory(title='Select a Folder to Delete! ')
os.rmdir(fodlertodlt)
mb.showinfo(title='Deleting Folder ?', message='Folder Deleted')
def list_directories():
folder = fd.askdirectory(title='Select a Directory to list it\'s files and folders ')
files = os.listdir(folder)
listfiles = Toplevel(windowframe)
listfiles.title(f'Files and Folders in {folder}')
listfiles.resizable(1,1)
listbox = Listbox(listfiles, selectbackground='gray', font=('courier',20))
listbox.place(relx=0,rely=0,relheight=1,relwidth=1)
i = 0
while i <len(files):
listbox.insert(END,files[i])
i += 1
#3 creating the window .. we must creat an object from the tkinter class and use it
windowframe = Tk()
windowframe.title('File Browser')
windowframe.geometry('300x300')
windowframe.resizable(0,0)
windowframe.config(background='orange')
windowframe.iconbitmap('icon.ico')
#4 creating the buttons to and calling the functions
Button (windowframe, text='Open a File',foreground='white', width=20, font='Courier',background='gray',command=open_file).place(x=50,y=50)
Button (windowframe, text='Open a Folder',foreground='white',width=20, font='Courier',background='gray',command=open_folder).place(x=50,y=100)
Button (windowframe, text='Delete a File',foreground='white',width=20,font='Courier',background='gray',command=delete_file).place(x=50, y= 150)
Button (windowframe, text='Delete a Folder',foreground='white',width=20,font='courier',background='gray',command=delete_folder).place(x=50, y=200)
Button (windowframe, text='List all Directories',foreground='white',width=20,font='courier',background='gray',command=list_directories).place(x=50, y=250)
windowframe.update()
windowframe.mainloop()
End of the Code <<<
Comment: please answer it ?? it got a project to present..

Comment: I can't reproduce any problem with your code. It works as expected except that there is no `os.startfile` on other systems than MS Windows. Check out: https://stackoverflow.com/questions/17317219/is-there-an-platform-independent-equivalent-of-os-startfile for a platform independent replacement for `os.startfile`



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2022:00:06/18/22', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python><tkinter><debug-information>', 'Title': 'it opens a directory after closing', 'ViewCount': 26, 'id': 72670650, 'user_AboutMe': '<p>From Afghanistan, Herat.\nStudying Computer Science at Ghalib University in the network department.\nI am a programmer, networker, and IT admin(Assistance).\nMostly doing network programming using python, getting ready for my first CCNA and CCNP certificate.\nTrying to code with python and create a website using HTML, CSS, and JavaScript.</p>\n', 'user_AccountId': 21657971.0, 'user_DisplayName': 'Wahid Anwari', 'user_Reputation': 33.0, 'user_Views': 8.0, 'user_id': 19362585.0}}