33from tkinter import *
44from tkinter .scrolledtext import ScrolledText
55
6+ from tkinter .ttk import *
7+ from tkinter import ttk
8+
69from Apps .Notepad .app import notepad , openFile
710
811import tkinter .filedialog as fd
@@ -172,6 +175,52 @@ def open_file():
172175 else :
173176 os .startfile (os .path .abspath (file ))
174177
178+ def new_file ():
179+ def close_new_file ():
180+ newfile .destroy ()
181+ app .deiconify ()
182+
183+ def create_new_file ():
184+ newfile_name = newfile_name_input .get ()
185+ newfile .destroy ()
186+ if newfile_name == "" :
187+ mb .showerror ("Error!" ,"We're not able to create this file !" )
188+ else :
189+ # extension = newfile_name.split(".")
190+ # print(extension[1])
191+ file = open (f'System/Users/User/Desktop/' + newfile_name , 'w' )
192+ file .write ("File created with MaxPyOS." )
193+ file .close ()
194+ mb .showinfo ("MaxPyOS - File Explorer" ,"File has been created with success !" )
195+ app .deiconify ()
196+ i = 0
197+ files = os .listdir ("System/Users/User/Desktop/" )
198+ listbox = Listbox (app , selectbackground = 'SteelBlue' , font = ("Arial" , 10 ))
199+ listbox .place (relx = 0 , rely = 0 , relheight = 1 , relwidth = 1 )
200+ scrollbar = Scrollbar (listbox , orient = VERTICAL , command = listbox .yview )
201+ scrollbar .pack (side = RIGHT , fill = Y )
202+ listbox .config (yscrollcommand = scrollbar .set )
203+ while i < len (files ):
204+ listbox .insert (END , files [i ])
205+ i += 1
206+
207+ app .withdraw ()
208+ newfile = Toplevel ()
209+ newfile .geometry ("400x400" )
210+ newfile .resizable (False , False )
211+ newfile .iconbitmap ("Apps/FileExplorer/icons/fileexplorer-icon.ico" )
212+ newfile .protocol ("WM_DELETE_WINDOW" , lambda : close_new_file ())
213+
214+ Label (newfile , text = "Enter file's name:" , font = ("Arial" , 10 )).pack ()
215+
216+ newfile_name_input = Entry (newfile , text = "new file name" , font = ("Arial" , 15 ))
217+ newfile_name_input .pack ()
218+
219+ newfile_name_input .delete (0 , END )
220+ newfile_name_input .insert (0 , "New file.txt" )
221+
222+ Button (newfile , text = "Create new file" , command = create_new_file ).pack ()
223+
175224 def list_files_in_folder ():
176225 i = 0
177226 files = os .listdir ("System/Users/User/Desktop/" )
@@ -190,12 +239,13 @@ def list_files_in_folder():
190239
191240 file = Menu (menubar , tearoff = 0 )
192241 file .add_command (label = "Open a file" , command = open_file )
242+ file .add_command (label = "New file" , command = new_file )
193243 file .add_command (label = "Delete a file" , command = delete_file )
194244 file .add_command (label = "Copy a file" , command = copy_file )
195245 file .add_separator ()
196246 file .add_command (label = "Delete a folder" , command = delete_folder )
197247 file .add_separator ()
198- file .add_command (label = "Update " , command = updatelist )
248+ file .add_command (label = "Refresh " , command = updatelist )
199249
200250 menubar .add_cascade (label = "File" , menu = file )
201251
0 commit comments