[英]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.