Need Help with Tkinter

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2005
Posts: 68
Reputation: danizzil14 is an unknown quantity at this point 
Solved Threads: 1
danizzil14's Avatar
danizzil14 danizzil14 is offline Offline
Junior Poster in Training

Need Help with Tkinter

 
0
  #1
Jul 8th, 2005
Ok, I've only been working with Python for something like 4 days now and I'm stuck trying to do a certain thing in Tkinter. Now, just to get you into the situation here. I've created a little program that has an entry bar and a go button. It says for you to enter in your name in the entry box and click the go button. What should happen is after the person enters in his/hers name and clicks the go button it should print something like Hello, "name" inside the window as a label or in a separate window as a label. but the best I can manage is something like:
def GoButtonClick(self, event)
print "Hello,", self.entryfield.get()

but that prints the Hello, Name in the prompt. Is it possible to do what I'm trying to do or am I thinking on to grand a scale?

Using: Windows ME, Tkinter, Python 3.something in the .20's

Help is appreciated. :cheesy:
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,043
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 934
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Need Help with Tkinter

 
0
  #2
Jul 8th, 2005
Check this code, you may be able to use portions for your project ...
[php]# Tkinter, explore the entry field

from Tkinter import *

def show():
# clear the label
label2.config(text='')
# get the enter1 text and show it in label2
label2.config(text='Hello ' + enter1.get())

# create root window
root = Tk()

# create label1
label1 = Label(root, text='Enter your name below:')
label1.pack(side=TOP, fill=X) # topmost

# creaet entry field
enter1 = Entry(root)
enter1.pack(side=TOP, fill=X) # below label1
# start entry1 empty
enter1.insert(0, '')
# put cursor into entry1 field
enter1.focus()
# you can either press the enter key or click the button to move text to label2
enter1.bind('<Return>', (lambda event: show()))

# create label2
label2 = Label(root, bg='yellow', anchor=W)
label2.pack(side=TOP, fill=X) # below entry1

# or get entry text clicking on button
btn1 = Button(root, text='Get Text', command=show)
btn1.pack(side=LEFT) # below label2

# start the event loop (run the program)
root.mainloop()
[/php]
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 68
Reputation: danizzil14 is an unknown quantity at this point 
Solved Threads: 1
danizzil14's Avatar
danizzil14 danizzil14 is offline Offline
Junior Poster in Training

Re: Need Help with Tkinter

 
0
  #3
Jul 10th, 2005
Well, looks as if it might work. But there is one thing, is it possible to make it print with an event bind?(at least i think that is what it is called) Mainly because I'm not familliar with the command = show thing.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 68
Reputation: danizzil14 is an unknown quantity at this point 
Solved Threads: 1
danizzil14's Avatar
danizzil14 danizzil14 is offline Offline
Junior Poster in Training

Re: Need Help with Tkinter

 
0
  #4
Jul 10th, 2005
Originally Posted by danizzil14
Well, looks as if it might work. But there is one thing, is it possible to make it print with an event bind?(at least i think that is what it is called) Mainly because I'm not familliar with the command = show thing.
much less the lambda thing
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,043
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 934
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Need Help with Tkinter

 
0
  #5
Jul 10th, 2005
Okay, here is a less complex version using just bind and passing an event argument to show() ...
[php]# Tkinter, explore the entry field (use bind, no lambda)

from Tkinter import *

def show(event):
# clear the label
label2.config(text='')
# get the enter1 text and show it in label2
label2.config(text='Hello ' + enter1.get())

# create root window
root = Tk()

# create label1
label1 = Label(root, text='Enter you name below:')
label1.pack(side=TOP, fill=X) # topmost

# creaet entry field
enter1 = Entry(root)
enter1.pack(side=TOP, fill=X) # below label1
# start entry1 empty
enter1.insert(0, '')
# put cursor into entry1 field
enter1.focus()
# you can either press the enter key or click the button to move text to label2
enter1.bind('<Return>', show) # bind to pressing of the ENTER key

# create label2
label2 = Label(root, bg='yellow', anchor=W)
label2.pack(side=TOP, fill=X) # below entry1

# or get entry text clicking on button
btn1 = Button(root, text='Get Text')
btn1.pack(side=LEFT) # below label2
btn1.bind('<Button-1>', show) # bind to left mouse click

# start the event loop (run the program)
root.mainloop()
[/php]
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC