|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
||||
|
||||
|
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?
__________________
IE QUOTE | PHP Manual | Google | C/C++ Compiler | Linux Tutorials | General Stuff Game Dev |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
||||
|
||||
|
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 |
|
#4
|
||||
|
||||
|
Give this a go
, if not attach your prgram so we can test itCode:
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 |
|
#5
|
||||
|
||||
|
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 |
|
#6
|
||||
|
||||
|
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. |
|
#7
|
||||
|
||||
|
thanx.. but what was i doing wrong?
|
|
#8
|
||||
|
||||
|
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. |
|
#9
|
||||
|
||||
|
hey if you get this in time.. get on yahooo =) want to show ya something
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Entry.get( ) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|