导入ScrollView模块会在kivy中禁用全屏模式

时间:2013-09-27 15:06:03

标签: kivy

包含该行,from kivy.uix.scrollview import ScrollView会使Config.set('graphics', 'fullscreen', '1')的效果无效,这样当导入ScrollView时,应用程序将变为窗口而不是全屏。如何在使用ScrollView时全屏显示我的应用程序?谢谢。

1 个答案:

答案 0 :(得分:3)

您似乎需要先定义配置。比较:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import kivy
kivy.require('1.7.1')

from kivy.config import Config
Config.set('graphics', 'fullscreen', 'auto')

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.scrollview import ScrollView 

class ImageApp(App):
    def build(self):
        layout = BoxLayout()
        button = Button(text="Exit", size_hint=(None, None))
        layout.add_widget(button)
        button.bind(on_press=exit)
        return layout

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

使用:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import kivy
kivy.require('1.7.1')

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.scrollview import ScrollView 

from kivy.config import Config
Config.set('graphics', 'fullscreen', 'auto')

class ImageApp(App):
    def build(self):
        layout = BoxLayout()
        button = Button(text="Exit", size_hint=(None, None))
        layout.add_widget(button)
        button.bind(on_press=exit)
        return layout

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

<强>更新

让我们试着看看这个行为。在ScrollView模块中,有一个kivy.metrics.sp用于计算滚动距离。所以实际上这段代码也不会让我们全屏显示:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import kivy
kivy.require('1.7.1')

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button

from kivy.metrics import sp
val = sp(1)

from kivy.config import Config
Config.set('graphics', 'fullscreen', 'auto')

class ImageApp(App):
    def build(self):
        layout = BoxLayout()
        button = Button(text="Exit", size_hint=(None, None))
        layout.add_widget(button)
        button.bind(on_press=exit)
        return layout

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

kivy.metrics.sp有以下定义:

from kivy.properties import dpi2px
def sp(value):
    return dpi2px(value, 'sp')

正在调用kivy.properties.dpi2px,顾名思义,将dpi转换为像素,因此需要计算屏幕dpi。看起来罪魁祸首就在这里。