Problem styling textbutton text [SOLVED]

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
TrickWithAKnife
Eileen-Class Veteran
Posts: 1261
Joined: Fri Mar 16, 2012 11:38 am
Projects: Rika
Organization: Solo (for now)
IRC Nick: Trick
Location: Tokyo, Japan
Contact:

Problem styling textbutton text [SOLVED]

#1 Post by TrickWithAKnife »

What I'd like to do is have a screen with many textbuttons, which I can customize the appearance for, including colour, size, background colour, hover colour and drop shadow.

I've tried a number of methods, with almost no success. The only thing I've been able to change is the background of the buttons.

I don't want to change the default style, as these particular buttons will be unique.

I've created a style as such:

Code: Select all

init python:

    style.text['Word List'].size = 45
    style.text['Word List'].hover_color = "#FF00FF"             # Pink
    style.text['Word List'].outlines = [ (0, "#0000FF", 1, 1) ] # Blue
    style.text['Word List'].color = "#FF0000"                   # Red
    style.text['Word List'].background = "#FFFF00"              # Yellow                      # Works
This is being referenced in a screen as shown:

Code: Select all

            viewport id "vp":
                draggable True
                
                grid 2 length_of_grid:
                    spacing 10
                    xfill True
                    ypos 140
                     
                    for i in range(0,len(all_vocab_set)):
                        $ currentword = (all_vocab_set[i])
                        $ currentwordsname = "vocab_" + currentword + ""
                        $ currentwordslevel = renpy.store.__dict__[currentwordsname].level 
                        $ currentwordsmeaning = renpy.store.__dict__[currentwordsname].meaning 
                        textbutton ("[currentword] [currentwordslevel]") style style.text["Word List"]: # Styles aren't being applied correctly
                            
                            action SetVariable("word_from_wordlist_that_was_clicked", currentwordsmeaning)
Any ideas on where I'm going wrong?
Last edited by TrickWithAKnife on Sat Jul 26, 2014 1:05 pm, edited 1 time in total.
"We must teach them through the tools with which they are comfortable."
The #renpy IRC channel is a great place to chat with other devs. Due to the nature of IRC and timezone differences, people probably won't reply right away.

If you'd like to view or use any code from my VN PM me. All code is freely available without restriction, but also without warranty or (much) support.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Problem styling textbutton text

#2 Post by PyTom »

textbutton (and it's friends like label and prompt) are a little odd, since they are actually two displayables - the Button itself, and the Text inside the Button. When you use style, you set the outer style, but not the inner one.

The fix is to use text_style in addition.

Code: Select all

textbutton ("[currentword] [currentwordslevel]") style style.button["Word List"] text_style style.text["Word List"]:
    ...
I'd also suggest not using an indexed style, and using a named style instead. When a named style is given to a textbutton, "_text" is appended to the style name to get the text style name.

Code: Select all

style word_list is button:
    background "#FFFF00"              # Yellow 

style word_list_text is text:
    size 45
    hover_color "#FF00FF"             # Pink
    outlines [ (0, "#0000FF", 1, 1) ] # Blue
    color "#FF0000"                   # Red
And then

Code: Select all

textbutton ("[currentword] [currentwordslevel]") style "word_list":
    ...
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

TrickWithAKnife
Eileen-Class Veteran
Posts: 1261
Joined: Fri Mar 16, 2012 11:38 am
Projects: Rika
Organization: Solo (for now)
IRC Nick: Trick
Location: Tokyo, Japan
Contact:

Re: Problem styling textbutton text

#3 Post by TrickWithAKnife »

It's working exactly how I want and the advice will come in helpful soon too. Thanks.
"We must teach them through the tools with which they are comfortable."
The #renpy IRC channel is a great place to chat with other devs. Due to the nature of IRC and timezone differences, people probably won't reply right away.

If you'd like to view or use any code from my VN PM me. All code is freely available without restriction, but also without warranty or (much) support.

Post Reply

Who is online

Users browsing this forum: No registered users