When i enter the text value in the Text Box and click on generate Button in the GUI Form generated from this Code it does not print the desired output, Instead I get the below error
Exception in Tkinter callback
Traceback (most recent call last):
File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/__init__.py", line 1699, in __call__
return self.func(*args)
File "/Users/Desktop/tk.py", line 28, in <lambda>
b1 = Button(root, text='Generate', command=(lambda e=ents:
fetch(e)))
File "/Users/Desktop/tk.py", line 7, in fetch
text = text[1].get()
TypeError: get() missing 1 required positional argument: 'index1'
from tkinter import *
fields = 'Section1','Section2'
def fetch(entries):
for text in entries:
field = text[0]
text = text[1].get()
print('%s \n%s\n' % ("\n====================================\n" + field + "\n====================================\n", text))
def makeform(root, fields):
entries = []
for field in fields:
row = Frame(root)
lab = Label(row, width=35, text=field, anchor='w')
ent = Text(row, height=10)
row.pack(side=TOP, fill=X, padx=15, pady=15)
lab.pack(side=LEFT)
ent.pack(side=RIGHT, expand=YES, fill=X)
entries.append((field, ent))
return entries
if __name__ == '__main__':
root = Tk()
root.title('Form')
#Text.get()
ents = makeform(root, fields)
root.bind('<Return>', (lambda event, e=ents: fetch(e)))
b1 = Button(root, text='Generate', command=(lambda e=ents: fetch(e)))
b1.pack(side=LEFT, padx=5, pady=5)
b2 = Button(root, text='Quit', command=root.quit)
b2.pack(side=LEFT, padx=5, pady=5)
root.mainloop()
Read the text Wiget Documentation and the issue is resolved, I used the index parameters in get method
CURRENT:
text = text[1].get()
MODIFY
text = text[1].get('1.0', 'end')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.