簡體   English   中英

如何更改Kivy Graph的背景顏色?

[英]How to change the background color of a kivy Graph?

是否存在與下面的屬性類似的屬性,用於更改Kivy中Graph的背景顏色?

test.kv

Graph:
    id: my_graph_id
    border_color = (0,0,0,0) # this is valid
    background_color = (0,0,0,0) # ?? this does not exist

在Python代碼中使用graph.background_color Kivy Garden Graph確實存在background_color屬性,如下所示。

main.py

from math import sin
from kivy.garden.graph import Graph, MeshLinePlot
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout


class RootWidget(BoxLayout):

    def __init__(self, **kwargs):
        super(RootWidget, self).__init__(**kwargs)

        graph = Graph(xlabel='X', ylabel='Y', x_ticks_minor=5, x_ticks_major=25, y_ticks_major=1,
                      y_grid_label=True, x_grid_label=True, padding=5,
                      x_grid=True, y_grid=True, xmin=-0, xmax=100, ymin=-1, ymax=1)

        graph.background_color = 0, 0, 1, 1    # blue color

        plot = MeshLinePlot(color=[1, 0, 0, 1])
        plot.points = [(x, sin(x / 10.)) for x in range(0, 101)]
        graph.add_plot(plot)
        self.add_widget(graph)


class GraphDemo(App):
    title = "Kivy Garden Graph - background_color"

    def build(self):
        return RootWidget()


if __name__ == "__main__":
    GraphDemo().run()

產量

Img01-Kivy Garden Graph background_color是藍色

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM