How to display mouse coords on screen?

I am trying to learn programing for the first time with panda and python, and I have two questions.

  1. I am trying to display the coordinates of the mouse on the screen as text. Attached is my attempt, cobbled together from the tilting ball maze tutorial.

my code doesn’t work. What is the bare minimum code required to do this?

from direct.showbase.ShowBase import ShowBase 
from panda3d.core import TextNode
from direct.gui.OnscreenText import OnscreenText

class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        if base.mouseWatcherNode.hasMouse():
          OnscreenText(text = base.mouseWatcherNode.getMouseX(), pos = (.5, .5), scale = .1, mayChange = True)
        
        OnscreenText(text = "yet Even MORE EPICfail!!!!", pos = (.5, .5), scale = .1, mayChange = True)        
app = MyApp()
app.run()
  1. What kind of language is created without any expletives? They are always the first things you learn. :smiling_imp:

Thanks for having a look

It takes a little while to wrap your head around tasks. :slight_smile:

from direct.showbase.ShowBase import ShowBase
from panda3d.core import TextNode
from direct.gui.OnscreenText import OnscreenText

class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        self.text = OnscreenText(pos = (0.5, 0.5), scale = 0.1, mayChange = True)
        taskMgr.add(self.textTask, 'textTask')

    def textTask(self, task):
        if base.mouseWatcherNode.hasMouse():
            self.text.setText(str(base.mouseWatcherNode.getMouseX()))
        else:
            self.text.setText('no mouse')
        return task.cont

app = MyApp()
app.run()