简体   繁体   中英

Changing color TabbedPannelHeader in Kivy

I tried many different ways, but nothing solve this. When I change the color of a button, for (0,0,1,1) I have blue. If I use the same list for TabbedPannel, I have dark blue, and for (0, 0, 1, 0) I have white. Is like I have a black background and I always have a mix of it and any other color, but I'm not able to get the specific color. This happens on Spinner too, but not with Labels or Buttons. What should I do? I tried use default_tab_cls, but, as I could imagine it just changes the default tab.

Edition after first answer:

This is the part I having problem. I call a function that returns my TabbedPanelHeader. Everything is ok with this.font_padrao is a custom font and this is working well. This example returns me white background and blue color font. If I change background_color to (0,0,1,1) the blue is different from the blue I have when I do the same thing ins Button for example. There, the blue is "real blue", not a "dark blue" or something like this.

return TabbedPanelHeader(text=nome, background_color = (0, 0, 1, 0), font_name=fonte_padrao, color = (0,0,1,1))

I'm on windows, so default background is black afaik, but maybe on other OSes there is different one .

In your main.py :

from functools import partial
import rotinas
Window.clearcolor = (1, 1, 1, 1) <-----
import sqlite3 as sql
from datetime import *

That's your white color, if you use alpha==0 in your coloring. Remove that line and you'll have the default Kivy background ie black .

Next thing, Label itself has no image as a background, therefore changing its background color either with variable or with canvas instrucctions results in a clear color. In widgets such as Spinner or basically anything that has different color than transparent most probably uses an image from atlas as a background(setting stuff from canvas is less efficient than changing pngs - at least more lines of code).

When you use a widget that has an image as a background, changing the backgroung color only tints the image that's used as background ie the atlas one. There is your problem, because you maybe want to have a clear color or use the TabbedPanelHeader -blue(tinted one). Two examples:

Here you have the tinted blue(the background_normal isn't necessary, it's set like that by default by kivy)

from kivy.lang import Builder
from kivy.base import runTouchApp
from kivy.uix.boxlayout import BoxLayout
Builder.load_string('''
<Test>:
    TabbedPanelHeader
        color: (0,0,1,1)
        text:'blaaaaaaa'
        background_color: (0, 0, 1, 1)
        background_normal: 'atlas://data/images/defaulttheme/tab_btn'
''')
class Test(BoxLayout):pass
runTouchApp(Test())

Here you have the standard, clear color(see the empty background_normal ):

from kivy.lang import Builder
from kivy.base import runTouchApp
from kivy.uix.boxlayout import BoxLayout
Builder.load_string('''
<Test>:
    TabbedPanelHeader
        color: (0,0,1,1)
        text:'blaaaaaaa'
        background_color: (0, 0, 1, 1)
        background_normal: ''
''')
class Test(BoxLayout):pass
runTouchApp(Test())

PS: Use pep8 or install one yourself( pip install pep8 ) and make your code more readable. You will have a lot of problems debugging that after a year, trust me. It may work well, but you killed whole point of python readability.

Also I saw some .db files in your zip, but didn't open them. The thing that you posted your database to someone you surely don't have a clue what will do with it is bad. Worse is even that you posted it publicly. Let's say you have in that database personal data, bank account numbers or whatever - you don't want to be responsible for loosing or misusing them, do you?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM