How to change button image at mouse hover over in tkinter in Python? -


i've started adventure python recently, please go easy on me :d

i've been working on 2nd program gui in tkinter couple of days now, , looks i've run wall.

it's game creates 2d map making 2d list.

each element of list created button tkinter object instance tile_basic_off image. far good.

should try bind each of these buttons 2 functions mouse over/mouse leave things go south...

it should work like:

mouse on -> change image tile_basic_on

mouse leave -> change tile_basic_off

however, once code below run (there function draws .grid() method) same, tiles not changing image @ mouse on or mouse leave.

here question-wise important piece of code. (note redmagenta var holding rgb, not typo)

from tkinter import * #python 3.4 here   def createmap (): #creates rows x columns 2d list - map     global rowsentryvar, columnsentryvar, maplist     maplist = []     row in range(rowsentryvar):         templist = []         column in range(columnsentryvar):             templist.append(button(root, bd=0, bg=redmagenta, activebackground=redmagenta))         maplist.append(templist) settilesproperties()   tilebasicoffimage = photoimage(file="resources/tile/tile_basic_off.png") tilebasiconimage = photoimage(file="resources/tile/tile_basic_on.png")  def turntileon (row, column): #changes tile image on     global maplist     maplist[row][column].configure(image=tilebasiconimage)     maplist[row][column].image = tilebasiconimage  def turntileoff (row, column): #changes tile image off     global maplist     maplist[row][column].configure(image=tilebasicoffimage)     maplist[row][column].image = tilebasicoffimage  def settilesproperties (): #sets basic properties apply tiles     global maplist, tilebasicoffimage     row in range(len(maplist)):         column in range(len(maplist[row])):             maplist[row][column].configure(image=tilebasicoffimage)             maplist[row][column].bind("<enter>", turntileon(row, column))             maplist[row][column].bind("<leave>", turntileoff(row, column)) 

what wrong code?

thanks , not tldring this. ;]


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

wso2esb - How to concatenate JSON array values in WSO2 ESB? -