简体   繁体   English

Kivy 不允许我使用全屏

[英]Kivy not Allowing me to use full screen

I'm trying to make a Kivy MP3 player type app but for some reason I'm not allowed to use my full screen ie.我正在尝试制作一个 Kivy MP3 播放器类型的应用程序,但由于某种原因我不允许使用我的全屏,即。 when my code looks like this当我的代码看起来像这样

from kivy.app import App
from kivy.uix.image import Image
from kivy.core.window import Window
from kivy.config import Config
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.core.audio import SoundLoader
from kivy.lang import Builder
class Application(App):
    def build(self):
       
        layout = BoxLayout(orientation="vertical")
       
        img = Image(source='myapp/logo1.png',size_hint=(1, .5),pos_hint={'center_x':0.7,"center_y":1},allow_stretch=True)
        button = Button(text="Click Here For Some Sweet Music",size_hint=(0.5,0.5),background_color=color,pos_hint={'center_x':0.7})
        button.bind(on_press=self.on_button_press)
        layout.add_widget(img)
        layout.add_widget(button)

Application().run()

I get a screen looking like我的屏幕看起来像在此处输入图片说明 but when I move the center x of the image to 1 I get an image looking like但是当我将图像的中心 x 移动到 1 时,我得到的图像看起来像在此处输入图片说明 So there is an "imaginary" box inside the window.所以窗口内有一个“虚构”的盒子。 I've tried changing the Config settings but it doesn't work.我试过更改配置设置,但它不起作用。 How would I make this box larger?我如何使这个盒子变大?

The Button is not the full width of the window because of the size_hint that you have assigned.由于您分配了size_hint ,因此Button不是窗口的全宽。 The Image is not the full width because the Image , by default, tries to maintain the aspect ratio of the source image. Image不是全宽,因为默认情况下Image试图保持source图像的纵横比。 You can fill the entire window y adjusting size_hint and changing keep_ratio :您可以填充整个窗口 y 调整size_hint并更改keep_ratio

class Application(App):
    def build(self):
        layout = BoxLayout(orientation="vertical")

        img = Image(source='myapp/logo1.png', size_hint=(1, .5), pos_hint={'center_x': 0.5},
                    allow_stretch=True, keep_ratio=False)
        button = Button(text="Click Here For Some Sweet Music", size_hint=(1.0, 0.5),
                        pos_hint={'center_x': 0.5})
        button.bind(on_press=self.on_button_press)
        layout.add_widget(img)
        layout.add_widget(button)
        return layout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM