By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,831 Members | 1,183 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,831 IT Pros & Developers. It's quick & easy.

Saving content of entry through save option in menu

P: 1
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.txt).
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
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/python
  2.  
  3. from Tkinter import *
  4. import fileinput
  5. import tkMessageBox
  6.  
  7. class AutoScrollbar(Scrollbar):
  8.     # a scrollbar that hides itself if it's not needed.  only
  9.     # works if you use the grid geometry manager.
  10.     def set(self,lo,hi):
  11.      #   if float(lo) <= 0.0 and float(hi) >= 1.0:
  12.       #      # grid_remove is currently missing from Tkinter!
  13.        #     self.tk.call("grid", "remove", self)
  14.         #else:
  15.          #   self.grid()
  16.         Scrollbar.set(self,lo,hi)
  17. """ def pack(self, **kw):
  18.         raise TclError, "cannot use pack with this widget"
  19.     def place(self, **kw):
  20.         raise TclError, "cannot use place with this widget"
  21.         """
  22.  
  23.  
  24. class myframe():
  25.     def __init__(self,parent):
  26.         self.master=parent
  27.         #Creating MenuBar
  28.         menubar=Menu(parent)
  29.         filemenu=Menu(menubar,tearoff=0)
  30.         filemenu.add_command(label="Save", command=self.file_save)
  31.         filemenu.add_command(label="Clear",command=self.clear_content)
  32.         filemenu.add_command(label="Exit",command=self.exit_window)
  33.         menubar.add_cascade(label="File", menu=filemenu)
  34.         #Display menu
  35.         parent.config(menu=menubar)
  36.  
  37.         #Creatin Canvas Object
  38.         vscrollbar = AutoScrollbar(parent)
  39.         vscrollbar.grid(row=0, column=1, sticky=N+S)
  40.         hscrollbar = AutoScrollbar(root, orient=HORIZONTAL)
  41.         hscrollbar.grid(row=1, column=0, sticky=E+W)
  42.         c_obj=Canvas(parent,height=400,width=400,yscrollcommand=vscrollbar.set,xscrollcommand=hscrollbar.set)
  43.         c_obj.grid(row=0, column=0, sticky=N+S+E+W)
  44.         vscrollbar.config(command=c_obj.yview)
  45.         hscrollbar.config(command=c_obj.xview)
  46.  
  47.         # make the canvas expandable
  48.         root.grid_rowconfigure(0, weight=1)
  49.         root.grid_columnconfigure(0, weight=1)
  50.  
  51.         # create canvas contents
  52.         frame = Frame(c_obj)
  53.         frame.rowconfigure(1, weight=1)
  54.         frame.columnconfigure(1, weight=1)
  55.  
  56.         frame1=Frame(parent)
  57.         label0= Label(frame1,text='Note:',font="Arial 20")
  58.         label0.grid(sticky=W)
  59.  
  60.         #Iterating note file for user
  61.         for line in fileinput.input(['note.txt']):
  62.             label1=Label(frame1,text=line,pady=0,padx=0,width=0)
  63.             label1.grid(sticky=W)
  64.         frame1.grid()
  65.  
  66.         count=0
  67.         for line in fileinput.input(['comp_list.txt']):
  68.             label=Label(frame,text=line)
  69.             entry=Entry(frame,width=10)
  70.             label.grid(row=count,sticky=W+E+N+S)
  71.             entry.grid(row=count,column=1,sticky=W+E+N+S )
  72.             count=count+1
  73.  
  74.         c_obj.create_window(0, 0, anchor=NW, window=frame)
  75.         frame.update_idletasks()
  76.         c_obj.config(scrollregion=c_obj.bbox("all"))
  77.  
  78.  
  79.     def file_save(self,entry):
  80.         print self.entry.get()
  81.         self.master.quit()
  82.     def clear_content(self):
  83.         self.master.quit()
  84.     def exit_window(self):
  85.         self.master.quit()    
  86.  
  87.  
  88. ##Program Starts from here        
  89. root = Tk()
  90. root.title("Component Detail")
  91. #Message Dialouge Box
  92. tkMessageBox.showinfo("Enter Value","Please Enter the value of component" )
  93. hello = myframe(root)
  94. root.mainloop()
  95.  
  96.  
  97.  
Thanks and Regards
Aug 27 '13 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.