Python Forum
[Tkinter] how to update label text from list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] how to update label text from list
#1
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 ?
Reply
#2
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.
Reply
#3
yes, spData[1:2] is elemnt of list items.

& my list is like this

['#', '336', '908', '120', '863', '789', '3', '\n']
Reply
#4
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.
Reply
#5
Sir,
error is

IndexError: list index out of range
Reply
#6
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?
Reply
#7
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
Reply
#8
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!
Reply
#9
(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 ?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Update label if there are no records in treeview TomasSanchexx 1 946 Aug-20-2023, 04:45 PM
Last Post: menator01
  [Tkinter] Can't update label in new tk window, object has no attribute tompranks 3 3,562 Aug-30-2022, 08:44 AM
Last Post: tompranks
  [Tkinter] The Text in the Label widget Tkinter cuts off the Long text in the view malmustafa 4 4,920 Jun-26-2022, 06:26 PM
Last Post: menator01
  How to update the list of a combo box in a QTableView panoss 10 6,262 Feb-05-2022, 03:24 PM
Last Post: panoss
  [Tkinter] Make my button text update? Skata100 1 2,043 Aug-07-2021, 05:37 AM
Last Post: deanhystad
  update text variable on label with keypress knoxvilles_joker 3 4,929 Apr-17-2021, 11:21 PM
Last Post: knoxvilles_joker
  How to read text in kivy textinput or Label jadel440 1 5,267 Dec-29-2020, 10:47 AM
Last Post: joe_momma
  [Kivy] Kivy text label won't shows up! AVD_01 1 2,944 Jun-21-2020, 04:01 PM
Last Post: AVD_01
  [Tkinter] Python 3 change label text gw1500se 6 4,722 May-08-2020, 05:47 PM
Last Post: deanhystad
  [PyQt] Python PyQt5 - Change label text dynamically based on user Input ppel123 1 13,786 Mar-20-2020, 07:21 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020