0

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

4

1 回答 1

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。看来罪魁祸首来了。

于 2013-09-27T17:05:40.340 回答