1
私はkivyとグラフの問題がthis issueに関連しているかどうか、私が間違っていたかどうかはわかりません。kivy:プロットとスクリーンマネージャ。プロットが表示されない
#! /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'
任意のアイデア私のプロットが表示されない理由はここに私の分は
メインファイルのですか? Githubので