The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Entry.get( )
Discuss Entry.get( ) in the Python Programming forum on Dev Shed. Entry.get( ) Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 14th, 2003, 08:17 PM
|
 |
Only the strong survives!!.
|
|
Join Date: Feb 2003
Location: A World of wonders.
|
|
|
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?
|

November 15th, 2003, 01:37 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
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
|

November 15th, 2003, 12:17 PM
|
 |
Only the strong survives!!.
|
|
Join Date: Feb 2003
Location: A World of wonders.
|
|
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
|

November 15th, 2003, 12:54 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
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
|

November 15th, 2003, 04:32 PM
|
 |
Only the strong survives!!.
|
|
Join Date: Feb 2003
Location: A World of wonders.
|
|
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
|

November 16th, 2003, 12:31 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
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 01:18 PM.
|

November 16th, 2003, 09:17 PM
|
 |
Only the strong survives!!.
|
|
Join Date: Feb 2003
Location: A World of wonders.
|
|
|
thanx.. but what was i doing wrong?
|

November 17th, 2003, 02:01 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
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.
|

November 17th, 2003, 02:04 AM
|
 |
Only the strong survives!!.
|
|
Join Date: Feb 2003
Location: A World of wonders.
|
|
|
hey if you get this in time.. get on yahooo =) want to show ya something
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|