Rollover Field

I’m trying to create and invisible box that when rolled over it calls a function. My original idea is to use an button who’s image is just a transparent image. but i can’t figure out how to get the current state (normal, rollover,pressed,dissabled)

It would be something like this in Pseudo-code:

self.button = DirectButton(... button attributes ...)

taskMgr.add(self.watcher,'watch')

def watcher(self,task):
     if self.button is rolled over:
          self.fun()

     return Task.cont

def fun(self):
     Do something here

If you can help at all on this or if you know an easier way to do this, it would be greatly appreciated. Thanks in advance

Use self.button.bind(DGG.ENTER, yourFunction).

Alright I’m having problems getting that to work, I have this test code:

import direct.directbase.DirectStart
from direct.showbase import DirectObject
from direct.showbase.ShowBaseGlobal import *
from direct.gui.DirectGui import *
from pandac.PandaModules import *

class World(DirectObject.DirectObject):
    def __init__(self):
        self.field1 = DirectButton(image = 'Images/field.png',scale = (.2,.2,.2),pos = (0,0,0), relief = None)
        self.field1.bind(DGG.ENTER,command = self.hello)
        self.field1.setTransparency(1)
        self.field1.show()
        
        base.mouseWatcherNode.showRegions(render2d,'gui-popup',0)
    
    def hello(self):
        print 'hello'

test = World()
run()

but,when I mouse over the image, it gives me the error

TypeError: hello() takes exactly 1 argument (2 given)

Thanks again for your help

Nevermind I figured it out I’m just a little slow some times :unamused: thanks for the help