Getting a class FileDialogDemo not found in this code. What am I doing wrong?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
"""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 |