User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 401,683 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,588 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Views: 2470 | Replies: 4
Reply
Join Date: Jul 2005
Location: Suisun CA
Posts: 68
Reputation: danizzil14 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
danizzil14's Avatar
danizzil14 danizzil14 is offline Offline
Junior Poster in Training

Help Need Help with Tkinter

  #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:
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2004
Location: Mojave Desert
Posts: 2,425
Reputation: vegaseat will become famous soon enough vegaseat will become famous soon enough 
Rep Power: 9
Solved Threads: 173
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
Kickbutt Moderator

Solution Re: Need Help with Tkinter

  #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  
Join Date: Jul 2005
Location: Suisun CA
Posts: 68
Reputation: danizzil14 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
danizzil14's Avatar
danizzil14 danizzil14 is offline Offline
Junior Poster in Training

Re: Need Help with Tkinter

  #3  
Jul 9th, 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  
Join Date: Jul 2005
Location: Suisun CA
Posts: 68
Reputation: danizzil14 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
danizzil14's Avatar
danizzil14 danizzil14 is offline Offline
Junior Poster in Training

Re: Need Help with Tkinter

  #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  
Join Date: Oct 2004
Location: Mojave Desert
Posts: 2,425
Reputation: vegaseat will become famous soon enough vegaseat will become famous soon enough 
Rep Power: 9
Solved Threads: 173
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
Kickbutt Moderator

Solution Re: Need Help with Tkinter

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Python Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Python Forum

All times are GMT -4. The time now is 7:40 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC