Python Forum
[Tkinter] HOW TO: Set [Label].config() by variable name reference?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] HOW TO: Set [Label].config() by variable name reference?
#4
cBox[0].config(**style(i))
Use [] not ()

cBox[0].config(**style[i])
def test_config(font, fg, bg):
    print(font, fg, bg)


style = [
  {'font': ('Liberation Mono', 20, 'bold'), 'fg': 'red3', 'bg': 'pink'},
  {'font': ('Liberation Mono', 20, 'normal'), 'fg': 'black',
   'bg': 'dark goldenrod'},
  {'font': ('Liberation Mono', 20, 'bold'), 'fg': 'dark goldenrod',
   'bg': 'light yellow'}]

test_config(**style[0])
test_config(**style[1])
test_config(**style[2])
Output:
('Liberation Mono', 20, 'bold') red3 pink ('Liberation Mono', 20, 'normal') black dark goldenrod ('Liberation Mono', 20, 'bold') dark goldenrod light yellow
Reply


Messages In This Thread
RE: HOW TO: Set [Label].config() by variable name reference? - by Yoriz - Apr-17-2019, 09:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  update text variable on label with keypress knoxvilles_joker 3 4,954 Apr-17-2021, 11:21 PM
Last Post: knoxvilles_joker
  Printing Variable into the label ardvci 5 3,137 Mar-19-2020, 09:35 PM
Last Post: joe_momma
  [Tkinter] Unable to save filepath to config.ini file using filedialog.askopenfilename JackMack118 10 5,036 Dec-29-2019, 08:12 PM
Last Post: JackMack118
  [Tkinter] Trying to display a variable in a label Jordansonatina 2 17,877 Oct-31-2019, 06:28 PM
Last Post: Jordansonatina
  [Tkinter] can't update label to include variable foxtreat 2 3,678 Dec-01-2018, 07:16 AM
Last Post: jfong
  printing option menu variable in label in Tkinter SmokerX 1 6,641 Jan-18-2018, 07:36 PM
Last Post: SmokerX

Forum Jump:

User Panel Messages

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