2017-01-16 71 views
0

我正試圖找到一個解決方案,將圖形嵌入到一個kivy窗口小部件中。似乎只有一個使用kivy garden graph(sin wave)的例子,並且在我的應用程序中難以實現。Kivy圖不會出現在窗口小部件中

這裏是我與

#!/usr/bin/kivy 
import kivy 


from random import random 
from kivy.app import App 
from kivy.lang import Builder 
from kivy.uix.screenmanager import ScreenManager, Screen 
from kivy.uix.gridlayout import GridLayout 
from kivy.uix.boxlayout import BoxLayout 
from kivy.uix.button import Button 
from kivy.uix.switch import Switch 
from kivy.uix.label import Label 
from kivy.garden.graph import Graph, MeshLinePlot 
from math import sin 
import matplotlib.pyplot as plt 
import matplotlib.animation as animation 
from kivy.graphics import * 

from kivy.config import Config 
Config.set('graphics', 'width', '800') 
Config.set('graphics', 'height', '480') 

Builder.load_string(""" 

<Menuscreen>: 
    #Handling the gesture event. 
    ScreenManager: 
     id: manager 
     Screen: 
      id: main_screen 
      name:'main_screen' 
      FloatLayout: 

       MyGraph: 
        size_hint: None, None 
        size: 800,600 
        pos: 25,25 



""") 

class MyGraph(Graph): 
    def __init__(self, **kwargs): 
     super(MyGraph, self).__init__(**kwargs) 
     self.xlabel = 'This is the X axis' 
     self.ylabel = 'This is the Y axis' 
     self.x_ticks_minor = 5 
     self.x_ticks_major = 25 
     self.y_ticks_major = 1 
     self.y_grid_label = True 
     self.x_grid_label = True 
     self.x_grid = True 
     self.y_grid = True 
     self.xmax = 100 
     self.xmin = -0 
     self.ymin = -1 
     self.ymax = 1 
     self.plot = MeshLinePlot(color=[1, 0, 0, 1]) 
     self.plot.points = [(x, sin(x/10.)) for x in range(0, 100)] 
     self.add_plot(self.plot) 

class MenuScreen(Screen): 
    pass 

sm = ScreenManager() 
menu_screen = MenuScreen(name='menu') 
sm.add_widget(menu_screen) 


class TestApp(App): 

    def build(self): 

     return sm 

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

工作的所有軸標籤似乎出現,但圖上的點不會出現在代碼。有什麼我失蹤,讓這個出現?預先感謝您的建議。

回答

0

Mostafar在Github上問同樣的問題,並感謝@Tshirtman,下面的答案提供:

mostafar評論2014年4月27日與@tshirtman聊天后,他發現了問題是與模版緩衝並通過改變線139圖形模塊的init.py給:

self._fbo = FBO(大小= self.size,with_stencilbuffer =假)

這將是可見在我的例子,但隨後就會有圖形(SmoothLinePlot)的新特性會帶來很多問題。

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

相關問題