Hi
I want to update 5 different label value from list items.
I am following below code.
self.dLabel1.configure(text = f"button clicked times {spData[1:2]}")
my problem is when label update it also add side brackets & single quote
button clicked times ['234']
I want label text as
button clicked times 234
how to solve this issue ?
What is spData? From the print it appears spData[1:2] is a list.
My guess is a spData is a list of numbers (spData = [1, 2, 3, 4, 5]) and you want to get the number at index 1. To do that use spData[1]. spData[1:2] returns a list of the entries from index 1 to index 1.
yes, spData[1:2] is elemnt of list items.
& my list is like this
['#', '336', '908', '120', '863', '789', '3', '\n']
So you will want to use:
self.dLabel1.configure(text = f"button clicked times {spData[1]}")
Now you will get a string instead of a list. No more brackets.
Sir,
error is
IndexError: list index out of range
If I run this:
spData = ['#', '336', '908', '120', '863', '789', '3', '\n']
text = f"button clicked times {spData[1]}"
print(text)
I see this:
Output:
button clicked times 336
Where is the disconnect between you and me? Is spData different than what I used above?
Yes sir
right according to print this works ok.
but when i print it on button then result is like this
# when i excute this program
self.dLabel1.configure(text = f" button clicked times {spData[1:2]}")
result is:
button clicked times ['336']
# when i write according to you generate error
self.dLabel1.configure(text = f"button clicked times {spData[1]}")
above code create error:
IndexError: list index out of range
I would debug with a bunch of print statements to understand exactly what is going on.
print('spData is a', type(spData), 'size =', len(spData))
# Since spData[1] is out of range
print('spData[0] is', type(spData[0]), spData[0])
A real puzzler!
(Apr-22-2020, 04:14 PM)deanhystad Wrote: [ -> ]I would debug with a bunch of print statements to understand exactly what is going on.
print('spData is a', type(spData), 'size =', len(spData))
# Since spData[1] is out of range
print('spData[0] is', type(spData[0]), spData[0])
A real puzzler!
Have you sort out problem ?