I am having trouble applying my functions to the list I retrieve from my tkinter text widget. The list is retrieved via a button command=lambda: get_list())
. I am trying to apply def func_1():
however it doesn't throw an error, it just runs it immediately before I've even entered any data.
dictionary = {
'A': '1',
'B': '2',
'C': '3'}
def get_list():
text_input = text.get("1.0", "end-1c").split("\n")
return text_input
def func_1(text_input):
x=0
while x < len(text_input):
text_replace = (text_input[x]).replace(',', '')
text_split = text_replace.split()
not_found = True
for key in dictionary:
if key in text_split:
result = dictionary[key]
return (result)
not_found = False
break
if not_found :
return ("Some Error Message")
x = x + 1
print(func_1(get_list()))
If I input a few lines;
1. A, D, E
2. B
3. C
It skips func_1
, and states the if not found text:
Some Error Message
I need it to get
the text widget input, split into a list at "\n"
, and run func_1
on as many items as were lines input into the widget.
func_1 should take each list item, replace any commas, and then split it into it's own list for the for loop.
I'm not sure how to break it down any differently than that.
Thanks for any advice!
I need it to get the text widget input, split into a list at "\n", and run func_1 on as many items as were lines input into the widget.
If that is the case, then you need to do exactly that: run func_1
on each line:
text_input = text.get("1.0", "end-1c").split("\n")
for line in text_input:
func_1(line)