Jul-21-2020, 03:05 AM
Getting a class FileDialogDemo not found in this code. What am I doing wrong?
"""Write a GUI-based program that allows the user to open, edit, and save text files.""" #imports breezy and EasyFrame from breezypythongui import EasyFrame #imports tkinter and file dialogue from tkinter import filedialog #imports system import sys class FileDialogDemo(EasyFrame): """Illustrates command buttons and user events.""" def __init__(self): """Sets up the window, label and buttons.""" EasyFrame.__init__(self, "File Dialog Demo") #a single label in the first row self.outputArea = self.addTextArea("", row = 0, column = 0, width = 80, height = 15) self.addButton(text = "Open", row = 1, column = 1, command = self.openFile) self.addButton(text = "Save", row =1, colummn = 2, command = self.saveFile) self.addButton(text = "New", row = 1, column = 3, command = self.newFile) #scrollbar rook = Tk() scrollbar = Scrollbar(root) scrollbar.pack(side = RIGHT, fill = Y) fList=Listbox(root, yscrollcommand=scrollbar.set) fList.pack(side = LEFT, fill = BOTH) scrollbar.config(command = fList.yview) #Event handling method. def openFile(self): """Pops up an open file dialog, and if a file is selected displays its text in the text area and its pathname in the title bar.""" fList = [("Python files", "*.py"),("Text files","*.txt")] fileName = tkinter.filedialog.askopenfilename(parent = self, filetypes = fList) if fileName !="": file = open(fileName, 'r') text = file.read() file.close() self.outputArea.setText(text) self.setTitle(fileName) def saveFile(self, fileName=None): if self.__file == None: #save as new file self.__file=asksaveasfilename(intialfile="Untitled.txt", defaultextenstions=".txt",filetypes=[("All Files","*.*"), ("Text Documents","*.txt")]) if self.__file=="": self.__file=None else: #try to save the file file = open(self.__file,"w") file.write(self.__thisTextArea.get(1.0,END)) #change the window title self.__root.title(os.path.basement(self.__file)+"-TextEditor") def newFile(self): self.__root.title("Untitled - TextEditor") self.__file = None self.__thisTextArea.delete(1.0,END) def main(): FileDialogDemo().mainloop() if __name__ == "__main__" : main() sys.exit()#exits system