kivy:情节和屏幕管理员;情节没有出现

时间:2016-10-31 17:24:52

标签: python kivy

我不确定我的kivy和图的问题是否与this issue有关,或者我做错了什么。这是我的分钟

主文件:

#! /usr/bin/env python
from math import sin

"""
Activate the touch keyboard. It is important that this part is on top
because the global config should be initiated first.
"""
from kivy.config import Config
Config.set('kivy', 'keyboard_mode', 'multi')

from kivy.app import App
# The Builder is used to define the main interface.
from kivy.lang import Builder
# use the screen manager to switch between screens
from kivy.uix.screenmanager import ScreenManager, Screen

from kivy.garden.graph import Graph, MeshLinePlot
from kivy.utils import get_color_from_hex as rgb


class MainScreen(Screen):
    pass


class DataScreen(Screen):
    def __init__(self, **kwargs):
        super(DataScreen, self).__init__(**kwargs)
        graph_theme = {'label_options': {'color': rgb('595959'), 'bold': False},
                       'background_color': rgb('DBE49A'),
                       'tick_color': rgb('999999'),
                       'border_color': rgb('808080')}

        self.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_theme)
        self.add_widget(self.graph)

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


class MyApp(App):
    """
    The settings App is the main app of the pHBot application.
    It is initiated by kivy and contains the functions defining the main interface.
    """


    def build(self):
        """
        This function initializes the app interface and has to be called "build(self)".
        It returns the user interface defined by the Builder.
        """
        Builder.load_file('phapp.kv')
        sm = ScreenManager()
        sm.add_widget(MainScreen())
        sm.add_widget(DataScreen())
        # returns the user interface defined by the Builder
        return sm


if __name__ == '__main__':
    MyApp().run()

kivy文件:

<MainScreen>:
    name: 'main'
    BoxLayout:
        orientation: 'vertical'
        Button:
            text: 'Go to data'
            font_size: 40
            on_release: app.root.current = 'data'
        Button:
            text: 'Exit'
            font_size: 40
            on_release: app.stop()

<DataScreen>:
    name: 'data'
    BoxLayout:
        orientation: 'vertical'
        Graph:
            size_hint_y: 0.9
        Button:
            size_hint: (1, 0.1)
            text: 'Start plotting data'
            font_size: 30
            on_release: root.plot_data()
        Button:
            size_hint: (1, 0.1)
            text: 'Back to main menu'
            font_size: 30
            on_release: app.root.current = 'main'

为什么我的情节没有出现?

1 个答案:

答案 0 :(得分:1)

在Github的mostafar问了同样的问题,感谢@tshirtman提供了following answer

  

与@tshirtman聊天后,他发现问题出在了   stencilbuffer并通过更改图形模块的 init .py的第139行   到:

self._fbo = Fbo(size=self.size, with_stencilbuffer=False)
     

在我的例子中可以看到,但是会有很多问题   具有图形的新功能(SmoothLinePlot)。

链接:https://github.com/kivy-garden/garden.graph/issues/7