奇异果弹出窗口更改图像大小

我在Kivy中有一个弹出窗口,我希望它有一个size_hint(0.5,0.5)的图像,但是当我尝试设置它时,图像会移动。

我当前的代码:

from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.popup import Popup
from kivy.uix.image import Image
import kivy
kivy.require('1.11.1')


class TestApp(App):
    def build(self):
        return Button(text='Open Popup',on_press=self.open)

    def open(self,button):
        Popup(title='Popup',size_hint=(0.5,0.5),content=Image(source='testing.png',0.5))).open()


TestApp().run()

当前代码给出以下结果:

奇异果弹出窗口更改图像大小

如果有人可以帮助我,那就太好了!

nokiafddfqq 回答:奇异果弹出窗口更改图像大小

您必须使用pos_hint参数。这应该解决它:

    def open(self,button):
        Popup(title='Popup',size_hint=(0.5,0.5),content=Image(source='testing.png',pos_hint={'center_x': 0.5,'center_y': 0.5})).open()

更多信息,https://blog.kivy.org/2014/01/positionsize-of-widgets-in-kivy/

,

您可以使用Pixlr Editor调整图像大小,然后使用乌龟将图像移动到所需位置:

import turtle
t = turtle.turtle
t.shape("testing.png")
#use the .forward() functions to move it
t.forward(10)
本文链接:https://www.f2er.com/3140712.html

大家都在问