黑色屏幕上的猕猴桃

时间:2019-07-05 19:21:59

标签: android python-3.x kivy

我已经用我的代码编写了我的应用程序代码,其中在主屏幕上,我有两个按钮,两个按钮都按下时转到其他页面,但分别是通话记录和屏幕抓图功能。 我认为将功能提供给按钮的路由存在问题。有人可以帮我吗?

此代码返回黑屏。

App.py

    class Home(Screen):
        pass
    class Root(BoxLayout):
        pass

class RecordButton(Button):
    # String Property to Hold output for publishing by Textinput
    output = StringProperty('')

    def record(self):
        #some code here
        self.ours(value)

    def ours(self,text):
        #some code here
        self.output = "ans is \"{}\"".format(sum)
        return sum

class SpeechApp(App):
    def build(self):
        #some code here
        return Root()


class CamApp(App):
          def screengrab(self,*largs):
                outname = self.fileprefix+'_%(counter)04d.png'
                Window.screenshot(name=outname)

          def build(self):

                # create a floating layout as base
                camlayout = FloatLayout(size=(600, 600))
                cam = Camera()        #Get the camera
                cam=Camera(resolution=(1024,1024), size=(300,300))
                cam.play=True         #Start the camera
                camlayout.add_widget(cam)

                button=Button(text='Take Picture',size_hint=(0.12,0.12))
                button.bind(on_press=self.screengrab)
                camlayout.add_widget(button)        
                self.fileprefix = 'snap'    
                return camlayout

class MainApp(App):
    def build(self):
        return Home()
if __name__ == '__main__':
    MainApp().run()

d.kv

<Home>:
hue: random()
canvas:
    Color:
        hsv: self.hue, .5, .3
    Rectangle:
        size: self.size
    Label:
        font_size: 42
        text: root.name
    Button:
        id=s_b
        text: 'Next screen'
        size_hint: None, None
        pos_hint: {'right': 1}
        size: 150, 50
        on_release: root.manager.current = root.manager.next()
    Button:
        id=cam_b
        text: 'Previous screen'
        size_hint: None, None
        size: 150, 50
        on_release: root.manager.current = root.manager.previous()


<Root>:
orientation: 'vertical'
RecordButton:
    id: record_button
    text: 'Record Speech'
    on_release: self.record()
    height: '50dp'
    size_hint_y: None

TextInput:
     #some code here

谢谢!

1 个答案:

答案 0 :(得分:0)

以下是可在多个屏幕上使用的示例代码

main.py

import kivy
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager,Screen
from kivy.lang import Builder

class MainWindow(Screen):
    pass

class SecondWindow(Screen):
    pass

class Manager(ScreenManager):
    pass

kv=Builder.load_file('kivyfile.kv')

class myapp(App):
    def build(self):
        return (kv)

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

kivyfile.kv

Manager:
    MainWindow:
    SecondWindow:

<MainWindow>:
    name:'main'
    GridLayout:
        cols:1
        Label:
            text:'This is the Main Window'
        Button:
            text:'Go to Second Window'
            on_release:
                app.root.current='second'

<SecondWindow>:
    name:'second'
    GridLayout:
        cols:1
        Label:
            text:'This is the Second Window'
        Button:
            text:'Go to Main Window'
            on_release:
                app.root.current='main'