Discuss Tkinter inpput box in the Python Programming forum on Dev Shed. Tkinter inpput box Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
Posts: 3,383
Time spent in forums: 1 Month 2 Weeks 3 Days 13 h 44 m 42 sec
Reputation Power: 383
Criminal that we must be careful with posts while you write careless slop.
And as rrashkin says, you didn't bother to indicate what is an "input box".
Code:
#Reference
import sys
try:
import Tkinter as tkinter
except:
import tkinter
top = tkinter.Tk()
t = tkinter.Text(top)
t.pack()
t.insert('1.0','The Text widget')
e = tkinter.Entry(top)
e.pack()
e.insert(0,'Entry widget')
class callback:
'''
Hmmm. lamba is simple.
'''
keys = set('text entry'.split())
def __init__(self,**kwargs):
# force pretty construction.
if not self.__class__.keys.issubset(set(kwargs)):
raise ValueError(
'%s(entry=EntryWidget,text=TextWidget)'%self.__class__.__name__)
self.__dict__.update(kwargs)
self.ouf = sys.stdout # open file ouf specifies the text and entry destination.
def __call__(self,*args,**kwargs):
w = self.ouf.write
w('-'*40)
w('\n'*2)
w('Text box content:\n')
# '1.0' specifies row 1, column 0, which is the start.
w(self.text.get('1.0',tkinter.END)) ##########You're looking for this line
w('\n')
w('Entry box content: '+self.entry.get()) ################## and for this line also
w('\n'*2)
tkinter.Button(top,
text='write content to ouf',
command=callback(text=t,entry=e)
).pack(side=tkinter.LEFT)
tkinter.Button(top,text='exit',command=top.destroy).pack(side=tkinter.RIGHT)
top.mainloop()
__________________
[code]Code tags[/code] are essential for python code!
Posts: 483
Time spent in forums: 3 Days 22 h 51 m 26 sec
Reputation Power: 63
Let's assume you want to do this:
Code:
'''tk_Entry_Button_simple.py
simple Tkinter Entry/Button example
'''
# with Python2 use 'import Tkinter as tk'
import tkinter as tk
def action():
# get the entry value
val = enter.get()
# display it in the root title as a test
root.title("name = %s" % val)
root = tk.Tk()
root.title("Enter your name")
# the entry
enter = tk.Entry(root, bg='yellow', width=50)
# the action button
button = tk.Button(root, text='Show name', command=action)
# pack widgets horizontally in the root window in order
enter.pack(side='left')
button.pack()
# start cursor in entry
enter.focus()
# start the event loop
root.mainloop()
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25
Posts: 5
Time spent in forums: 46 m 21 sec
Reputation Power: 0
Quote:
Originally Posted by Dietrich
Let's assume you want to do this:
Code:
'''tk_Entry_Button_simple.py
simple Tkinter Entry/Button example
'''
# with Python2 use 'import Tkinter as tk'
import tkinter as tk
def action():
# get the entry value
val = enter.get()
# display it in the root title as a test
root.title("name = %s" % val)
root = tk.Tk()
root.title("Enter your name")
# the entry
enter = tk.Entry(root, bg='yellow', width=50)
# the action button
button = tk.Button(root, text='Show name', command=action)
# pack widgets horizontally in the root window in order
enter.pack(side='left')
button.pack()
# start cursor in entry
enter.focus()
# start the event loop
root.mainloop()