Aksel2099
Aksel2099

Reputation: 61

how to index your tkinter labels?

I am new to python and tkinter, and in my program i create multiple labels and that works well, but my problem is that i need to re-configer my buttons later on for example if button X clicked then change 3rd label color ect and all my labels have same name ll229, I've tried to use an index like ll229[3].config(do something) but it didnot work.

def update_ref_str():
  for i in range(ref_counter):

  ref_codes_str[i].set(ref_codes[i])
  ref_obj_per_codes_str[i].set(ref_obj_per_code[i])
  ref_time_needed_str[i].set(ref_time_needed_per_task[i])

  ll229 = Label(f2, textvariable = ref_codes_str[i] , bg='springgreen2',fg="gray23")
  ll229.config(font=("Helvetica", 13))
  ll229.place(bordermode=OUTSIDE, height=18, width=100, x=573, y=100 + 20*i )

  ll33 = Label(f2, textvariable = ref_obj_per_codes_str[i] , bg='springgreen2' , fg="gray23")
  ll33.config(font=("Helvetica", 13))
  ll33.place(bordermode=OUTSIDE, height=18, width=59, x=677, y=100 + 20*i)

  ll44 = Label(f2, textvariable = ref_time_needed_str[i] , bg='springgreen2',fg="gray23")
  ll44.config(font=("Helvetica", 13))
  ll44.place(bordermode=OUTSIDE, height=18, width=58, x=740 , y=(100 + 20*i))

Upvotes: 0

Views: 537

Answers (1)

10SecTom
10SecTom

Reputation: 2664

This question shows an example of something similar to what you are after, but using entry widgets

example with entry widgets

More or less - if you set the name of your label, e.g, name='l{}'.format(i), you could then reference them via the parent frame f2.

get the text:

f2.children['l1'].get()

similarly, configure:

f2.children['l1'].config(......)

Upvotes: 1

Related Questions