如何在猕猴桃中更改按钮大小?

时间:2018-12-22 21:50:55

标签: python kivy

我正在使用kivy用Python编写程序,无法更改在两个屏幕之间来回切换的按钮的大小

我想不出为什么我无法使用“ size:75,50”之类的内容来更改其大小的原因,是因为该类是从Screen而不是Button继承的?

Python文件:

import kivy
from kivy.app import App
kivy.require("1.10.1")
from kivy.uix.label import Label
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen
from kivy.uix.screenmanager import ScreenManager

class ScreenRoot(Screen):   
    pass

class OtherScreen(Screen):   
    pass

class ScreenUpkeep(ScreenManager):    
    pass

view = Builder.load_file("main.kv")

    class MainApp(App):
        def build(self):
            return view

if __name__ == "__main__":
    MainApp().run()

对应的.kv文件:

ScreenUpkeep:
    ScreenRoot:
    OtherScreen:    

<ScreenRoot>:
    name: "rootmain"
    Button:
        text: "Next Screen"
        font_size: 40
        on_release: app.root.current = "other"
        size: 75, 50
<OtherScreen>:
    name: "other"
    Button:
        text: "Return"
        font_size: 40
            on_release: app.root.current = "rootmain"

我只希望能够更改按钮的大小,以便在每个屏幕上包含更多内容,例如文本和图片。

1 个答案:

答案 0 :(得分:0)

您必须禁用size_hint,以便更好地显示它,我将更改按钮的字体:

Button:
    text: "Next Screen"
    font_size: 12
    on_release: app.root.current = "other"
    size: 75, 50
    size_hint: None, None # <---

enter image description here

相关问题