•
•
•
•
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
![]() |
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:
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:
•
•
Join Date: Oct 2004
Location: Mojave Desert
Posts: 2,425
Reputation:
Rep Power: 9
Solved Threads: 173
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]
[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!
•
•
Join Date: Oct 2004
Location: Mojave Desert
Posts: 2,425
Reputation:
Rep Power: 9
Solved Threads: 173
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]
[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!
![]() |
•
•
•
•
•
•
•
•
DaniWeb Python Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Tkinter exception (Python)
- TKinter tough time (Python)
- Tkinter: protecting text in the Entry widget (Python)
- Wondering about new windows in Tkinter (Python)
Other Threads in the Python Forum
- Previous Thread: Compiling Python
- Next Thread: Wondering about new windows in Tkinter



Linear Mode