| | |
Need Help with Tkinter
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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:
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!
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!
![]() |
Similar Threads
- 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
| Thread Tools | Search this Thread |
address aliased anydbm app bash beginner bits changecolor cipher class clear conversion coordinates corners cturtle curves definedlines development dictionary dynamic events examples excel external feet file float format ftp function gui handling homework iframe images import info input java keycontrol line linux list lists loan loop matching mouse number numbers output parsing path permissions port prime programming projects py2exe pygame pymailer python random rational raw_input recursion recursive scrolledtext searchingfile shebang singleton split string strings table tails terminal text thread threading time tkinter tlapse tooltip tuple tutorial type ubuntu unicode url urllib urllib2 valueerror variable whileloop windows word wx.wizard wxpython xlwt






