Monday 10 September 2012

building simple applications with EasyGui library



i have been working on the python GUI library from few days now and found this amazing library to build simple gui application in matter of mins.

EasyGui uses the Tkinter to create the various gui components, its not as complex as PyQt or pygtk but fair enough to create a applications

here is example of simple file viewer which can be used to open a text files or code file for preview

#demo applicatio to create gui application using the easygui python library 

#importing the library file 
from easygui import *
import os
import sys

#simple application to browse and view files

#declaring the class fileviewer
class fileviewer:

    def __init__(self):
        #file open prompt
        self.menu()
        
    def menu(self):
        ch=indexbox('Simple File Viewer','Menu',['View File','Exit'])
        if ch ==0:
            #open file select and opne the file
            self.open_file()
            self.menu()
        elif ch ==1:
            #exit the applicaiton
            sys.exit()
            

    def open_file(self):
        #open the file in codebox
        file_name=fileopenbox("please select file to be opened")
        filename = os.path.normpath(file_name)
        text = open(filename,'rb').read()
        codebox("Contents of file " + filename, text=text)
        
        
if __name__ == '__main__':
    fileviewer()