【发布时间】:2016-07-23 11:46:26
【问题描述】:
我正在使用 kivy 1.9.1 构建一个纸牌游戏。我通过 size_hint 让卡片正确显示,相对于根窗口的大小。卡片类继承自图像类并且工作得很好。我意识到我需要使卡片可点击,所以我修改了类以继承自按钮类。由于某种原因,这与图像的大小不同。背景 .png 文件变形。请帮忙。这让我发疯了。我通常关闭 size_hint 以避免这个问题,但我需要根据根窗口大小缩放所有内容。
ScreenManagement:
CardTableScreen:
<Card>:
size_hint: (.25, .25)
pos_hint: ({'left': .05})
<CardTableScreen>:
name: 'cardTable'
Card:
name: 'card0'
id: card0
pos: (self.width *.20 , root.height / 2)
Card:
name: 'card1'
id: card1
pos: (self.width * .75, root.height / 2)
Card:
name: 'card2'
id: card2
pos: (self.width * 1.30 , root.height / 2)
Card:
name: 'card3'
id: card3
pos: (self.width * 1.85, root.height / 2)
Card:
name: 'card4'
id: card4
pos: (self.width * 2.40, root.height / 2)
Label:
name: 'handType'
id: handType
pos: (-(card0.width *.125), root.height * .30)
font_size: '18sp'
<Layout>:
orientation: 'vertical'
canvas.before:
Color:
rgba: 0,.25,0,1
Rectangle:
pos: self.pos
size: self.size
蟒蛇:
from kivy.uix.button import Button
class(Button): pass
【问题讨论】:
-
请根据How to create a Minimal, Complete, and Verifiable example 指南分享您的代码以供此社区提供帮助。
标签: python image button scale kivy