Saving content of entry through save option in menu

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • getmeuser
    New Member
    • Aug 2013
    • 1

    Saving content of entry through save option in menu

    Hello Friends

    Actually I want to save the content of entry using Save Option in menu.I can directly use the e.get() but problem is I am creating entry and label depending upon total count in a file(comp_lis.t xt).
    And that is created easily but what I need is to save the content of each entry box through menubar,so when I clicked on Save in menubar all content of entry will be saved say in some file. I dont know how exactly that could be done.Here is my piece of code. PLease let me know what should I add in it.
    Here is my code
    Code:
    #!/usr/bin/python
    
    from Tkinter import *
    import fileinput
    import tkMessageBox
    
    class AutoScrollbar(Scrollbar):
        # a scrollbar that hides itself if it's not needed.  only
        # works if you use the grid geometry manager.
        def set(self,lo,hi):
         #   if float(lo) <= 0.0 and float(hi) >= 1.0:
          #      # grid_remove is currently missing from Tkinter!
           #     self.tk.call("grid", "remove", self)
            #else:
             #   self.grid()
            Scrollbar.set(self,lo,hi)
    """ def pack(self, **kw):
            raise TclError, "cannot use pack with this widget"
        def place(self, **kw):
            raise TclError, "cannot use place with this widget"
            """
    
    
    class myframe():
    	def __init__(self,parent):
    		self.master=parent
    		#Creating MenuBar
    		menubar=Menu(parent)
    		filemenu=Menu(menubar,tearoff=0)
    		filemenu.add_command(label="Save", command=self.file_save)
    		filemenu.add_command(label="Clear",command=self.clear_content)
    		filemenu.add_command(label="Exit",command=self.exit_window)
    		menubar.add_cascade(label="File", menu=filemenu)
    		#Display menu
    		parent.config(menu=menubar)
    		
    		#Creatin Canvas Object
    		vscrollbar = AutoScrollbar(parent)
    		vscrollbar.grid(row=0, column=1, sticky=N+S)
    		hscrollbar = AutoScrollbar(root, orient=HORIZONTAL)
    		hscrollbar.grid(row=1, column=0, sticky=E+W)
    		c_obj=Canvas(parent,height=400,width=400,yscrollcommand=vscrollbar.set,xscrollcommand=hscrollbar.set)
    		c_obj.grid(row=0, column=0, sticky=N+S+E+W)
    		vscrollbar.config(command=c_obj.yview)
    		hscrollbar.config(command=c_obj.xview)
    		
    		# make the canvas expandable
    		root.grid_rowconfigure(0, weight=1)
    		root.grid_columnconfigure(0, weight=1)
    		
    		# create canvas contents
    		frame = Frame(c_obj)
    		frame.rowconfigure(1, weight=1)
    		frame.columnconfigure(1, weight=1)
    		
    		frame1=Frame(parent)
    		label0= Label(frame1,text='Note:',font="Arial 20")
    		label0.grid(sticky=W)
    		
    		#Iterating note file for user
    		for line in fileinput.input(['note.txt']):
    			label1=Label(frame1,text=line,pady=0,padx=0,width=0)
    			label1.grid(sticky=W)
    		frame1.grid()
    				
    		count=0
    		[B]for line in fileinput.input(['comp_list.txt']):
    			label=Label(frame,text=line)
    			entry=Entry(frame,width=10)
    			label.grid(row=count,sticky=W+E+N+S)
    			entry.grid(row=count,column=1,sticky=W+E+N+S )
    			count=count+1[/B]
    			
    		c_obj.create_window(0, 0, anchor=NW, window=frame)
    		frame.update_idletasks()
    		c_obj.config(scrollregion=c_obj.bbox("all"))
    	
    
    	def file_save(self,entry):
    		print self.entry.get()
    		self.master.quit()
    	def clear_content(self):
    		self.master.quit()
    	def exit_window(self):
    		self.master.quit()	
    	
    		
    ##Program Starts from here		
    root = Tk()
    root.title("Component Detail")
    #Message Dialouge Box
    tkMessageBox.showinfo("Enter Value","Please Enter the value of component" )
    hello = myframe(root)
    root.mainloop()
    Thanks and Regards
Working...