Posts: 20
Threads: 7
Joined: Jun 2018
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 ?
Posts: 6,806
Threads: 20
Joined: Feb 2020
Apr-22-2020, 01:07 PM
(This post was last modified: Apr-22-2020, 01:07 PM by deanhystad.)
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.
Posts: 20
Threads: 7
Joined: Jun 2018
yes, spData[1:2] is elemnt of list items.
& my list is like this
['#', '336', '908', '120', '863', '789', '3', '\n']
Posts: 6,806
Threads: 20
Joined: Feb 2020
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.
Posts: 20
Threads: 7
Joined: Jun 2018
Sir,
error is
IndexError: list index out of range
Posts: 6,806
Threads: 20
Joined: Feb 2020
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?
Posts: 20
Threads: 7
Joined: Jun 2018
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
Posts: 6,806
Threads: 20
Joined: Feb 2020
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!
Posts: 20
Threads: 7
Joined: Jun 2018
(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 ?
|