簡體   English   中英

對 size_hint、python、kivy 沒有影響

[英]No effects on size_hint , python, kivy

我嘗試更改 Python、Kivy 中按鈕的 size_hint,但是我放在那里的每個值按鈕的大小保持不變.. 因為 pos 正在改變,但對於 size_hint 沒有,如果我從 pos 更改為 pos_hint button is stuck in the corner of the window and from there i cant change nothing... also i tried to stick the pos of the button on a position where is a text in the photo but every time when i resize the kivy window the button和圖像正在改變他們的 position .. 我該如何解決這個問題? 謝謝!!

from kivy.app import App
from kivy.uix.image import Image
from kivy.uix.button import Button
from random import choice


class MyImage(Image):
    images = ["Q1.png", "Q2.png", "Q3.png"]  # ........

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        correct = Button(pos=(200, 200), size_hint=(.1, .1), on_release=self.random_image, background_color=(1, 1, 1, 0.2))
        self.add_widget(correct)
        self.random_image()

    def random_image(self, *_):
        self.source = choice(self.images)


class RandomQuestionApp(App):
    def build(self):
        return MyImage()


randomApp = RandomQuestionApp()
RandomQuestionApp().run()

嘗試使用 size 而不是 size_hint。

correct = Button(
    pos=(200, 200),
    size=(100, 100), 
    on_release=self.random_image, 
    background_color=(1, 1, 1, 0.2)
)

尺寸:這是用於 static 小部件的尺寸,需要兩個 arguments 即(寬度,高度)。 按鈕的默認大小 = (100, 100)。

size_hint:這用於按鈕的動態調整大小並提供大小提示。 它包含兩個 arguments 即寬度和高度它可以是浮動值。默認情況下,所有小部件都有它們的 size_hint=(1, 1)。

如果沒有任何東西影響按鈕大小,您的動態將不會做任何事情。 另一方面,大小將定義按鈕的固定大小,其中 100x100 是默認值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM