vendredi 17 novembre 2017

Set background Image from Entry value

So I am currently trying to have a tkinter window change it's background image depending on what "Chapter" the user has input. This is what I have so far.

#admin data
Character = tk.Label(admindata, bg = bgc, text = (str('CharacterName')+':'))
Character.grid(column = 1, row= 1, pady= padysize, sticky=tk.N+tk.S+tk.E+tk.W)
Characterent = tk.Entry(admindata, bd=5)
Characterent.grid(column =2, row = 1, padx= padxsize, sticky=tk.N+tk.S+tk.E+tk.W)


DWBA = tk.PhotoImage(file = "DWBA.png")
DWIH = tk.PhotoImage(file = "DWIH.png")
DWDW = tk.PhotoImage(file = "DWDW.png")

def ldbgi():
    if Chapterent.get is None:
        space = DWDW
    elif Chapterent.get() == 'Blood Angels':
        space = DWBA
    elif Chapterent.get() == 'Iron Hands':
        space = DWIH
    else:
        space = DWDW
    return space

try:
    ldbgi()
except NameError:Chapterent = None

When I try running it, I get the error that space is not defined. Any help would be appreciated. I am new to python but this program is my way of learning it.

Aucun commentaire:

Enregistrer un commentaire