how to show words when hover on an imagebutton

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
ippherita
Regular
Posts: 27
Joined: Fri May 09, 2014 1:46 pm
Contact:

how to show words when hover on an imagebutton

#1 Post by ippherita »

Hi, I want to show some words beside the mouse when i hover on an imagebutton'

I was trying to use the tooltip thing, but i cant get it to work

this is my code:

Code: Select all

screen stats:
    imagebutton:
        idle "SmartSelect_20190102-003134_Samsung Notes - Copy.jpg"
        xpos 0.04
        ypos 0.25
        tooltip "Nobel"
and then to show it at the start:

Code: Select all

label start:
    call screen stats
it showed this:
Image

My mouse is hovering on the logo (can't show in the printscreen), but no words come out.

What did i do wrong?

User avatar
wyverngem
Miko-Class Veteran
Posts: 615
Joined: Mon Oct 03, 2011 7:27 pm
Completed: Simple as Snow, Lady Luck's Due,
Projects: Aether Skies, Of the Waterfall
Tumblr: casting-dreams
itch: castingdreams
Location: USA
Contact:

Re: how to show words when hover on an imagebutton

#2 Post by wyverngem »

https://renpy.org/doc/html/screen_actio ... ip#Tooltip

Code: Select all

screen tooltip_test:

    default tt = Tooltip("No button selected.")

    frame:
        xfill True

        has vbox

        textbutton "One.":
            action Return(1)
            hovered tt.Action("The loneliest number.")

        textbutton "Two.":
            action Return(2)
            hovered tt.Action("Is what it takes.")

        textbutton "Three.":
            action Return(3)
            hovered tt.Action("A crowd.")

        text tt.value

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3785
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: how to show words when hover on an imagebutton

#3 Post by Imperf3kt »

I was recently shown this super cool method.
viewtopic.php?f=51&t=47205
It makes some text appear next to the mouse when hovering any kind of button.

I posted some additional info there too, which explains how to style the text and even add a background.

Just make sure to put it at the bottom of a screen, or it'll appear below all of your buttons.


Or you could use the modern tooltip class.

Code: Select all

screen stats:
    imagebutton:
        idle "SmartSelect_20190102-003134_Samsung Notes - Copy.jpg"
        xpos 0.04
        ypos 0.25
        tooltip "Nobel"
        
        $ tooltip = GetTooltip()

        if tooltip:
            text "[tooltip]"
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

ippherita
Regular
Posts: 27
Joined: Fri May 09, 2014 1:46 pm
Contact:

Re: how to show words when hover on an imagebutton

#4 Post by ippherita »

Hi @Imperf3kt

I have tried both methods, but both of them don't work.

First is the MouseToolTip method, this is my code:

Code: Select all

default mtt = MouseTooltip(Text(""))

screen stats:
    add mtt
    imagebutton:
        idle "SmartSelect_20190102-003134_Samsung Notes - Copy.jpg"
        xpos 0.04
        ypos 0.25
        hovered mtt.Action(Text("Nobel"))
When try to run the game, the game did not launched, but this come out:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00start.rpy", line 185, in script
    python:
  File "renpy/common/00start.rpy", line 186, in <module>
    renpy.execute_default_statement(True)
  File "game/image.rpy", line 42, in set_default
    default mtt = MouseTooltip(Text(""))
  File "game/image.rpy", line 42, in <module>
    default mtt = MouseTooltip(Text(""))
NameError: name 'MouseTooltip' is not defined

Second is the modern tooltip class method:

Code: Select all

screen stats:
    imagebutton:
        idle "SmartSelect_20190102-003134_Samsung Notes - Copy.jpg"
        xpos 0.04
        ypos 0.25
        tooltip "Nobel"


    $tooltip = GetTooltip()

    if tooltip:
        text "[tooltip]"
The game actually run, but nothing happen when i move my mouse over the picture.

So I am not sure what happened, or did I do anything wrong?

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3785
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: how to show words when hover on an imagebutton

#5 Post by Imperf3kt »

In the first instance, you probably don't have the file, from what the error message tells me. You need to either download the file from github and put it in your game folder, or copy the code into one of your files already in your game folder.

As to the second, you have a black background, and there is no positioning information for the tooltip.
My guess is that the default text color, is black?
I can assume then, that the code works, but you can't see it doing so because you're displaying black on black.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

ippherita
Regular
Posts: 27
Joined: Fri May 09, 2014 1:46 pm
Contact:

Re: how to show words when hover on an imagebutton

#6 Post by ippherita »

First method:
I am an idiot to think i can see words when the background is dark.

now i have added a sketch background

my code is:
Image
(easy to copy version below)

Code: Select all

screen stats:
    add "sketch1548944620282.png"
    imagebutton:
        idle "SmartSelect_20190102-003134_Samsung Notes - Copy.jpg"
        xpos 0.04
        ypos 0.25
        tooltip "Nobel"

    $tooltip = GetTooltip()
    if tooltip:
        text "[tooltip]"
then same thing. My mouse is hovering the picture, but no words come out,
Image


I am thinking to stop figuring this method and try to get the second method figured out first.


2nd Method:
I am an idiot for not putting the mouse-tooltip.rpy into the game folder.

Now I have put it into the game folder.

my code is this:
Image
easy to copy version below:

Code: Select all

default mtt = MouseTooltip(Text(""))

screen stats:
    add mtt
    imagebutton:
        idle "SmartSelect_20190102-003134_Samsung Notes - Copy.jpg"
        xpos 0.04
        ypos 0.25
        hovered mtt.Action(Text("Nobel"))
It now show this:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00start.rpy", line 185, in script
    python:
  File "renpy/common/00start.rpy", line 186, in <module>
    renpy.execute_default_statement(True)
  File "game/script.rpy", line 20, in set_default
    default mtt = MouseTooltip(Text(""))
  File "game/script.rpy", line 20, in <module>
    default mtt = MouseTooltip(Text(""))
  File "game/mouse_tooltip.rpy", line 16, in __init__
    self.pad_x = padding.get('x', 0)
AttributeError: 'NoneType' object has no attribute 'get'
Did i do something wrong when copy pasting the mouse_tooltip.rpy into the game folder?

User avatar
IrinaLazareva
Veteran
Posts: 399
Joined: Wed Jun 08, 2016 1:49 pm
Projects: Legacy
Organization: SunShI
Location: St.Petersburg, Russia
Contact:

Re: how to show words when hover on an imagebutton

#7 Post by IrinaLazareva »

The button must have action(). If you don't need an action, use:

Code: Select all

action NullAction()
i.e. for the first method:

Code: Select all

    imagebutton:
        idle "SmartSelect_20190102-003134_Samsung Notes - Copy.jpg"
        xpos 0.04
        ypos 0.25
        action NullAction()
        tooltip "Nobel"

ippherita
Regular
Posts: 27
Joined: Fri May 09, 2014 1:46 pm
Contact:

Re: how to show words when hover on an imagebutton

#8 Post by ippherita »

Oh nice! that worked!

Now I just need to get it to the right place! Need to figure out the mtt method
and what "AttributeError: 'NoneType' object has no attribute 'get' " means

thank you so much Imperf3kt and IrinaLazareva!

Especially Imperf3kt, you have been a really great help!

ippherita
Regular
Posts: 27
Joined: Fri May 09, 2014 1:46 pm
Contact:

Re: how to show words when hover on an imagebutton

#9 Post by ippherita »

Hi Imperf3kt, I decided to try out the original code from the mousetooltip.

I basically just copy and paste:
Image
(actual code):

Code: Select all

screen tooltip_test:
add mtt

vbox:
    textbutton "One.":
        action Return(1)
        hovered mtt.Action(Text("The loneliest number."))
        
label start:
    show screen tooltip_test
But what I got is this:
Image
and when i close the renpy, i got this show up
Image


So i think it might have some indentation problem, so i changed the indentation a bit.
Image

Code: Select all

screen tooltip_test:
    add mtt

    vbox:
        textbutton "One.":
            action Return(1)
            hovered mtt.Action(Text("The loneliest number."))

label start:
    show screen tooltip_test
And I got this, same as what I have when i try to run my game. (Yes, i did changed the indentation in my game.)
Image

Can you tell me what did I do wrong?

ippherita
Regular
Posts: 27
Joined: Fri May 09, 2014 1:46 pm
Contact:

Re: how to show words when hover on an imagebutton

#10 Post by ippherita »

Sorry, I am an idiot.

Imperf3kt, Please ignore my last post.

The demo version from the MouseToolTip works.

I need to copy paste the code in the DEMO folder, not the one on the introduction.






Mine interpretation about the MouseToolTip on imagebutton does not.

Code: Select all

label start:


    call screen stats
    return

default mtt = MouseTooltip(Text(""))

screen stats:
    add mtt
    imagebutton:
        idle "SmartSelect_20190102-003134_Samsung Notes - Copy.jpg"
        xpos 0.04
        ypos 0.25
        action NullAction()
        hovered mtt.Action(Text("Nobel"))
Same problem persist.
I am still troubleshooting on this:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00start.rpy", line 185, in script
    python:
  File "renpy/common/00start.rpy", line 186, in <module>
    renpy.execute_default_statement(True)
  File "game/script.rpy", line 39, in set_default
    default mtt = MouseTooltip(Text(""))
  File "game/script.rpy", line 39, in <module>
    default mtt = MouseTooltip(Text(""))
  File "game/mouse_tooltip.rpy", line 16, in __init__
    self.pad_x = padding.get('x', 0)
AttributeError: 'NoneType' object has no attribute 'get'

ippherita
Regular
Posts: 27
Joined: Fri May 09, 2014 1:46 pm
Contact:

Re: how to show words when hover on an imagebutton

#11 Post by ippherita »

WOOHOOOO Finally got it!
It is the padding!
i did not define the padding!

My code was this. I did not have the padding at the "default mtt = MouseTooltip(Text("")"

Code: Select all

default mtt = MouseTooltip(Text(""))

screen stats:
    add mtt
    imagebutton:
        idle "SmartSelect_20190102-003134_Samsung Notes - Copy.jpg"
        xpos 0.04
        ypos 0.25
        action NullAction()
        hovered mtt.Action(Text("Nobel"))
Now added padding, it works! phew!

Code: Select all

default mtt = MouseTooltip(Text(""), padding={"x": 10, "y": -10})

screen stats:
    add mtt
    imagebutton:
        idle "SmartSelect_20190102-003134_Samsung Notes - Copy.jpg"
        xpos 0.04
        ypos 0.25
        action NullAction()
        hovered mtt.Action(Text("Nobel"))
woohoo! now words come out when i hover them!

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3785
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: how to show words when hover on an imagebutton

#12 Post by Imperf3kt »

Glad it worked out for you, but the credit should go to Human Bolt Diary. All I did was give you a link.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

Post Reply

Who is online

Users browsing this forum: Google [Bot]