unable to set textbutton color style [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
User avatar
Keul
Regular
Posts: 49
Joined: Wed May 06, 2009 3:42 am
Location: France - Strasbourg
Contact:

unable to set textbutton color style [Solved]

#1 Post by Keul » Sun Jan 13, 2013 5:20 pm

Hi,

I've made a music room using this tutorial : http://www.renpy.org/doc/html/rooms.html#music-room
I want to change the color of the text when it's the selected music.
(tr[fr] contains music titles, music the filenames, music_room_musics the musics displayed in music-room)

Edit: WORKING SOLUTION:

Code: Select all

init python:
    style.musicroom_musiclabel = Style(style.button_text)
    style.musicroom_musiclabel.background = Frame("images/interface/music_library_button.png", 25, 25)
    style.musicroom_musiclabel.hover_background = Frame("images/interface/music_library_button_hover.png", 25, 25)
    style.musicroom_musiclabel.selected_background = Frame("images/interface/music_library_button_selected.png", 25, 25)
    style.musicroom_musiclabel_button_text.color = "#FF0000"
    style.musicroom_musiclabel_button_text.hover_color = "#0000FF"
    style.musicroom_musiclabel_button_text.selected_color = "#00FF00"
    
screen music_room:
    side "c r":
        area (67, 110, 775, 457)
        viewport id "vp":
            draggable True
            mousewheel True
            vbox:
                for k in music_room_musics:
                    textbutton tr["fr"].music[k] action [mr.Play(music[k]), SelectedIf(renpy.music.get_playing() == music[k])] style "musicroom_musiclabel" text_style "musicroom_musiclabel_button_text"
Old code that doesn't work: (note the missing text_style attribute)

Code: Select all

init python:
    style.musicroom_musiclabel = Style(style.button_text)
    style.musicroom_musiclabel.background = Frame("images/interface/music_library_button.png", 25, 25)
    style.musicroom_musiclabel.hover_background = Frame("images/interface/music_library_button_hover.png", 25, 25)
    style.musicroom_musiclabel.selected_background = Frame("images/interface/music_library_button_selected.png", 25, 25)
    style.musicroom_musiclabel.color = "#FF0000"
    style.musicroom_musiclabel.hover_color = "#0000FF"
    style.musicroom_musiclabel.selected_color = "#00FF00"
    
screen music_room:
    side "c r":
        area (67, 110, 775, 457)
        viewport id "vp":
            draggable True
            mousewheel True
            vbox:
                for k in music_room_musics:
                    textbutton tr["fr"].music[k] action [mr.Play(music[k]), SelectedIf(renpy.music.get_playing() == music[k])] style "musicroom_musiclabel"
Problem, the background change but not the text color.
I've tried to apply the style to the text directly the following thing :

Code: Select all

                    textbutton Text(tr["fr"].music[k],style="musicroom_musiclabel") action [mr.Play(music[k]), SelectedIf(renpy.music.get_playing() == music[k])] style "musicroom_musiclabel"
Problem: hover_ and selected_ aren't transmitted and the text-color is always red

Is it a bug or Am I doing something wrong?
Last edited by Keul on Mon Jan 14, 2013 8:46 am, edited 2 times in total.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: unable to set textbutton coor style

#2 Post by nyaatrap » Sun Jan 13, 2013 9:20 pm

style.***_button_text.color changes textbutton color.
In the screen language, text_color changes it.

User avatar
Keul
Regular
Posts: 49
Joined: Wed May 06, 2009 3:42 am
Location: France - Strasbourg
Contact:

Re: unable to set textbutton coor style

#3 Post by Keul » Sun Jan 13, 2013 10:13 pm

style.musicroom_musiclabel_button_text.color = "#FF0000"
style.musicroom_musiclabel_button_text.hover_color = "#0000FF"
style.musicroom_musiclabel_button_text.selected_color = "#00FF00"
doesn't work. :(
textbutton Text(tr["fr"].music[k]) action [mr.Play(music[k]), SelectedIf(renpy.music.get_playing() == music[k])] text_color "#FFFF00"
throws an error (about text_color being not a valid argument)

really strange

thanks for your help anyways

Will continue to search for information on text_color

User avatar
Keul
Regular
Posts: 49
Joined: Wed May 06, 2009 3:42 am
Location: France - Strasbourg
Contact:

Re: unable to set textbutton color style

#4 Post by Keul » Mon Jan 14, 2013 8:43 am

OK, problem solved, with

Code: Select all

    style.musicroom_musiclabel_button_text.color = "#FF0000"
    style.musicroom_musiclabel_button_text.hover_color = "#0000FF"
    style.musicroom_musiclabel_button_text.selected_color = "#00FF00"
and

Code: Select all

textbutton tr["fr"].music[k] action [mr.Play(music[k]), SelectedIf(renpy.music.get_playing() == music[k])] style "musicroom_musiclabel" text_style "musicroom_musiclabel_button_text"
In fact, to change the attribute of the text button in the textbutton, we should not use style but text_style (you can change the name of the text style but then, you have to initialize it with "style.newstyle = Style(style.button_text)" and make sure that there's no "Text()" that would erase styles.

Post Reply

Who is online

Users browsing this forum: Ocelot