Kivy 应用程序显示在屏幕左下角

问题描述 投票:0回答:1

我的 Kivy 应用程序显示在手机屏幕的左下角(您可以在共享屏幕截图中看到)。但我想将其设为全屏。我在“buildozer.spec”文件中将“全屏”值设置为 1。但没有任何改变.这是我的代码:

from kivy.app import App
from kivy.core.window import Window
from kivy.uix.gridlayout import GridLayout
from kivy.uix.widget import Widget
from kivy.uix.image import Image
from kivy.clock import Clock
from kivy.uix.behaviors import ButtonBehavior
from kivy.core.audio import SoundLoader

Window.size = (320,640)

opart = False
vpart = False
rpart = False

och = False
vch = False
rch = False

ofin = False
vfin = False
rfin = False

fin = True

snd_part = SoundLoader.load("part.wav")
music = SoundLoader.load("music.wav")
music.play()

class Orange(ButtonBehavior,Image):
    def __init__(self,**kwargs):
        super(Orange,self).__init__(**kwargs)
        self.source = "obal.png"
        self.size = (85,113)
        self.pos = (32,300)
    def on_press(self):
        global opart
        opart = True
        Clock.schedule_interval(self.todown,0.1)
    def todown(self,*args):
        global och
        if not och:
            snd_part.play()
            self.source = "effect.png"
            och = True
        else:
            self.x = 28
            self.source = "esma.png"
        if self.y > 250:
            self.y -= 4
        else:
            self.y = 250
            global ofin,fin
            ofin = True
            if vfin and rfin and fin:
                fin = False
                win.kill_platform()

class Violet(ButtonBehavior,Image):
    def __init__(self,**kwargs):
        super(Violet,self).__init__(**kwargs)
        self.source = "vbal.png"
        self.size = (85,113)
        self.pos = (117,364)
    def on_press(self):
        global vpart
        vpart = True
        Clock.schedule_interval(self.todown,0.1)
    def todown(self,*args):
        global vch
        if not vch:
            snd_part.play()
            self.source = "effect.png"
            vch = True
        else:
            self.x = 113
            self.source = "yaxsiki.png"
        if self.y > 250:
            self.y -= 4
        else:
            self.y = 250
            global vfin,fin
            vfin = True
            if ofin and rfin and fin:
                fin = False
                win.kill_platform()

class Red(ButtonBehavior,Image):
    def __init__(self,**kwargs):
        super(Red,self).__init__(**kwargs)
        self.source = "rbal.png"
        self.size = (85,113)
        self.pos = (202,300)
    def on_press(self):
        global rpart
        rpart = True
        Clock.schedule_interval(self.todown,0.1)
    def todown(self,*args):
        global rch
        if not rch:
            snd_part.play()
            self.source = "effect.png"
            rch = True
        else:
            self.x = 198
            self.source = "varsan.png"
        if self.y > 250:
            self.y -= 4
        else:
            self.y = 250
            global rfin,fin
            rfin = True
            if ofin and vfin and fin:
                fin = False
                win.kill_platform()

class Platform(Widget):
    def __init__(self,**kwargs):
        super(Platform,self).__init__(**kwargs)
        self.size = (320,640)
        self.bgimage = Image(source = "bg.jpg")
        self.bgimage.size = (320,640)

        self.obeta = False
        self.vbeta = False
        self.rbeta = False

        self.obal = Orange()

        self.vbal = Violet()
        self.rbal = Red()
        Clock.schedule_interval(self.moveOrange,0.1)
        Clock.schedule_interval(self.moveViolet,0.1)
        Clock.schedule_interval(self.moveRed,0.1)

        self.bgimage.add_widget(self.obal)
        self.bgimage.add_widget(self.vbal)
        self.bgimage.add_widget(self.rbal)

        self.add_widget(self.bgimage)
    def moveOrange(self,*args):
        if not opart:
            if not self.obeta:
                 self.obal.y += 2
            else:
                self.obal.y -= 2
            if self.obal.y <= 280:
                self.obeta = False
            if self.obal.y >= 320:
                self.obeta = True
    def moveViolet(self,*args):
        if not vpart:
            if not self.vbeta:
                self.vbal.y += 1
            else:
                self.vbal.y -= 1
            if self.vbal.y <= 344:
                self.vbeta = False
            if self.vbal.y >= 384:
                self.vbeta = True
    def moveRed(self,*args):
        if not rpart:
            if not self.rbeta:
                self.rbal.y += 3
            else:
                self.rbal.y -= 3
            if self.rbal.y <= 280:
                self.rbeta = False
            if self.rbal.y >= 320:
                self.rbeta = True

class Platform2(Widget):
    def __init__(self,**kwargs):
        super(Platform2,self).__init__(**kwargs)
        self.size = (320,640)
        self.bgimage = Image(source = "bg.jpg")
        self.bgimage.size = (320,640)
        self.add_widget(self.bgimage)


class MainApp(App):
    def build(self):
        self.layout = GridLayout()
        self.platform = Platform()
        self.layout.add_widget(self.platform)
        return self.layout
    def kill_platform(self):
        self.platform = Platform2()
        self.layout.add_widget(self.platform)

win = MainApp()

win.run()

这里你可以看到截图。这就是它在我手机上的显示方式:

enter image description here

python kivy window size fullscreen
1个回答
0
投票

Window.size = (320,640)
行替换为:

from kivy.utils import platform

if platform not in ["android", "ios"]:
    Window.size = (320,640)

旁注,您可能想要将使用 320x640 像素数或至少小于它的属性更改为

size_hint=(1,1)
之类的内容。对于大多数人来说这个答案可能不清楚,但这是我能做的最好的事情

© www.soinside.com 2019 - 2024. All rights reserved.