如何在不中断Kivy程序的情况下关闭屏幕

时间:2015-07-10 13:27:57

标签: python screen kivy

我是初学者,因为编程已经使用了之前的论坛,该论坛获得了简单问题的帮助。 我目前正在寻找一种方法来关闭屏幕而不会中断我的程序,我正在使用“线程”继续执行命令,而程序在循环中。

MAIN

from kivy.app import App
from kivy.uix.screenmanager import Screen
from kivy.properties import ObjectProperty
from kivy.core.audio import SoundLoader
from time import sleep
import thread

class Display(Screen):
    myslider = ObjectProperty(None)

    def get_number(self):
        occupancy = format(self.myslider.value)
        print "value = ",occupancy

def display_screen():
    thread.start_new_thread(myApp().run, ())


def remove_screen():
    Screen.disabled()

def ring():
    sound = SoundLoader.load('ring.wav')
    if sound:
        sound.play()

class myApp(App):

    def build(self):
        return Display()


if __name__ == '__main__':
    ring()
    sleep(2)
    display_screen()
    sleep(7)
    remove_screen()

KV档案

#:import random random.random

<Display>:
    orientation: 'vertical'
    myslider: slider
    canvas:
        Color:
            rgb: 1, 1, 1
        Rectangle:
            source: 'data/images/background.jpg'
            size: self.size

    BoxLayout:
        padding: 10
        spacing: 10
        size_hint: 1, None
        pos_hint: {'top': 1}
        height: 44
        Image:
            size_hint: None, None
            size: 24, 24
            source: 'data/logo/kivy-icon-24.png'
        Label:
            height: 24
            text_size: self.size
            color: (1, 1, 1, .8)
            text: 'Kivy 1.9.0.'
            valign: 'middle'

    GridLayout:
        cols: 2
        Label:
            text: 'Please enter \nthe number of occupants?'
            bold: True
            font_name: 'data/fonts/DejaVuSans.ttf'
            font_size: 22
            halign: 'center'

        Slider:
            id: slider
            min: 0.0
            max: 15.0
            value: 1.0
            step: 1.0
            orientation: "horizontal"
            width: "38dp"

        Label
            text: ''

        Label
            text: '{}'.format(slider.value)
            halign: 'center'
            valign: 'top'
            bold: True
            text_size: self.size
            font_size: 18

    Button:
        text: 'Enter'
        size_hint_y: None
        height: '50sp'
        on_release: root.get_number()

我离开了remove_screen功能,因为这是我在研究中发现的。但不行。

0 个答案:

没有答案