python - 为什么用旋转调整窗口大小会干扰 UI 布局,包括 kivy 中的图像
问题描述
旋转图像并调整窗口大小后,图像未移动假定位置。在我的假设中,图像总是移动到左侧疼痛的中心。请告诉我解决方案。
该代码实现了在左侧和右侧生成带有疼痛(区域窗口)的窗口。左侧被假定为菜单栏。假设右侧通过旋转来操纵图像。如果您在窗口上移动鼠标,图像将根据您的鼠标距离旋转。
我的环境。
- macOS:10.14.5
- 基维:1.11.1
- 康达的 Python:3.6.8。
from cmath import sqrt
from kivy.app import App
from kivy.core.window import Window
from kivy.graphics.context_instructions import LoadIdentity
from kivy.input import MotionEvent
from kivy.properties import NumericProperty
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.image import Image
from kivy.lang import Builder
Builder.load_string("""
<Example>:
orientation:"horizontal"
BoxLayout:
orientation:"vertical"
size_hint:0.5,1 # rate of win, this is menubar.
canvas.before:
Color:
rgba: 0, 0, 0.5, 1
Rectangle:
pos: self.pos
size: self.size
Button:
size:1,0.5
Button:
size:1,0.5
FloatLayout:
id: near_layout
pos_hint: {'x':0.5,'y':0}
size_hint:0.5,1
canvas.before:
Color:
rgba: 0, 1, 0, 1
Rectangle:
pos: self.pos
size: self.size
Image:
id:img
center: near_layout.center
canvas.before:
Rotate:
angle: root.angle
axis: 0,0,1
origin: self.center
source: 'kivy.jpeg'
""")
class Example(App, BoxLayout):
angle = NumericProperty(0)
def build(self):
Window.bind(on_resize=self.on_resize)
return self
def on_resize(self, obj, x, y):
LoadIdentity()
self.img = self.ids.img # type:Image
self.img.reload() # Necessary,if not, image disappeared
def on_touch_move(self, touch):
self.angle += sqrt((touch.ppos[0] - touch.pos[0]) ** 2 + (touch.ppos[1] - touch.pos[1]) ** 2).real
print("pos:%s,size:%s" % (self.ids.near_layout.pos, self.ids.near_layout.size))
if __name__ == "__main__":
Example().run()
解决方案
推荐阅读
- swift - 三元运算符未正确处理零数据
- javascript - 带日程的云功能
- java - Alternatives to RecyclerView?
- twilio - 使用 Twilio 函数将 JSON 解析为数组 javascript
- javascript - 用纯 Javascript 重写 jQuery 调整大小函数(包括 codepen)
- angular - 外部 Firebase API 运行两次
- javascript - 是否可以在 Kendo UI 调度程序上增加网格线的宽度,以便在时间轴视图中更明显地显示哪一天?
- vue.js - Ag-grid - 事件和方法 (Vuejs)
- f# - 如何创建一个列表来检查字符串中的字符并返回每个字母的计数和其余字母的 0?
- html - 在电子邮件模板的 CSS 样式方面需要帮助