Thread: Entry.get( )

    #1
  1. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407

    Entry.get( )


    If i wanted to get chars of the entry function using get()( entry.get() ). i created a button so that once click it can print out the values on the konsole
    its something like so..

    Code:
    entry = Entry(frame,fg="blue")
      entry.pack()
      G = entry.get()
      
      button = Button(frame,text="Get",command=self.data(self.G))
      button.pack(side=LEFT)
     
     def data(self,g):
      print g
    but its not working for me any help?
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Hi X, dont know if this work buy there is .self.G in your code, so if you pass 'G' instead?

    Code:
    entry = Entry(frame,fg="blue")
      entry.pack()
      G = entry.get()
      
      button = Button(frame,text="Get",command=self.data(G))
      button.pack(side=LEFT)
     
     def data(self,g):
      print g
    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407
    Ya i tried it that way as well does not seem to work but im still tring other ways.. to see if i can get this working
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Give this a go , if not attach your prgram so we can test it
    Code:
        entry = Entry(frame,fg="blue")
        entry.pack()
        self.G = entry.get()
      
        button = Button(frame,text="Get",command=self.data)
        button.pack(side=LEFT)
    
    def data(self):
        print self.G
    Mark
    programming language development: www.netytan.com Hula

  8. #5
  9. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407
    Ok this is what got.. i changed it around a bit.. trying to get it to work and still nothing

    Code:
    #!/usr/bin/env python
    
    
    from Tkinter import *
    def printData(self,text=""):
     print text
     
    root  = Tk()
    frame = Frame(root,relief=GROOVE,border=1,height=32, width=32)
    frame.pack_propagate(0)
    frame.master.title("My ****y Program")
    
    
    v = StringVar()
    
    Label(frame,textvariable=v,font=("helvetica",12)).pack()
    v.set("New Text!")
    v.get()
    
    buttonvar = StringVar()
    buttonvar.set("Green")
    
    entry =  Entry(frame,fg="blue")
    text  =  entry.get()
    button = Button(frame,text="Print",command=v.set(v))
    button.pack()
    entry.pack()
    
    
    root.mainloop()
    yet i cant find a descent tutorial anyware on the net, or not even for socket program

    this part
    button = Button(frame,text="Print",command=v.set(v))
    i tried
    button = Button(frame,text="Print",command=printData(text))
    nothing happends, even with self.text
  10. #6
  11. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Here you go! All working, i'm betting you where getting a blank string printed to the console window.. this is because the text box starts of blank so this is the value being saved to your variable..

    I tried running your code but i ended up with a blank window so i just wrote you an example from scatch! On another point you should use tabs instead if spaces when you indent your code, not only does it lead to slightly smaller programs but its easier to see where the blocks are

    Code:
    #!/usr/bin/env python
    
    import Tkinter as tk
    
    class window:
    	
    	def __init__(self, root):
    		frame = tk.Frame(root)
    		
    		self.button = tk.Button(frame, text = 'Print this..', command = self.output)
    		self.entry = tk.Entry()
    		self.entry.pack()
    		self.button.pack()	
    	
    		frame.pack()
    		
    	def output(self):
    		print 'entry =>', self.entry.get() or 'Nothing'
    		
    if __name__ == '__main__':
    
    	root = tk.Tk()
    	window(root)
    	root.mainloop()
    Mark.
    Last edited by netytan; November 16th, 2003 at 02:18 PM.
    programming language development: www.netytan.com Hula

  12. #7
  13. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407
    thanx.. but what was i doing wrong?
  14. #8
  15. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    the problem was that you where saving the value of the entry box while it was empty (''), what you need to do is call entry.get() from within your button function so that it loads the new value each time you click the button

    Mark.
    programming language development: www.netytan.com Hula

  16. #9
  17. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407
    hey if you get this in time.. get on yahooo =) want to show ya something

IMN logo majestic logo threadwatch logo seochat tools logo