Kivy:I 想要 window 大小的按钮堆叠在屏幕顶部
Kivy:I want window-sized buttons to be stacked on top of the screen
我想要 window 大小的不透明黑色按钮堆叠在屏幕顶部
当我按下不透明的黑色按钮时,按钮将消失,下面的屏幕将可见。
我尝试过,但一直失败。
下面是我的代码(.py
)
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.image import Image
from kivy.animation import Animation
from kivy.clock import Clock
class First_Screen(Screen, BoxLayout):
pass
class ScreenManagement(ScreenManager):
pass
presentation = Builder.load_file("main.kv")
class TubucApp(App):
def build(self):
return presentation
TubucApp().run()
这是我的 .kv
文件:
ScreenManagement:
transition:
First_Screen:
<First_Screen>: #<-i want fullscreen-sized opaque black button covers
#up this screen and will be disappear when i press the button
name: 'First_Screen'
BoxLayout:
orientation: 'horizontal'
spacing: 50
padding: [50, 50, 50, 50]
canvas:
Rectangle:
pos: self.pos
size: self.size
source: 'image/background.jpg'
Button:
id: campustown
width: 40
pos_hint: {'x' : 0, 'y':.45}
size_hint: [.6,.1]
background_normal:'image/test.png'
background_down:'image/test2.png'
border: (0,0,0,0)
font_size: 15
text: 'campus-town'
这两张图片展示了我想要完成的事情:
我该怎么做?
Python代码
- 从
class First_Screen()
中删除 BoxLayout
片段 - Py
class First_Screen(Screen):
pass
kv 文件
- 为按钮添加一个
on_release
事件
- 将
background_normal
设置为background_down
片段-kv
<First_Screen>:
name: 'First_Screen'
Button:
id: campustown
background_normal: 'image/test.png'
background_down: 'image/test2.png'
border: (0,0,0,0)
font_size: 15
text: 'campus-town'
on_release:
self.background_normal = self.background_down
输出
我想要 window 大小的不透明黑色按钮堆叠在屏幕顶部 当我按下不透明的黑色按钮时,按钮将消失,下面的屏幕将可见。 我尝试过,但一直失败。
下面是我的代码(.py
)
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.image import Image
from kivy.animation import Animation
from kivy.clock import Clock
class First_Screen(Screen, BoxLayout):
pass
class ScreenManagement(ScreenManager):
pass
presentation = Builder.load_file("main.kv")
class TubucApp(App):
def build(self):
return presentation
TubucApp().run()
这是我的 .kv
文件:
ScreenManagement:
transition:
First_Screen:
<First_Screen>: #<-i want fullscreen-sized opaque black button covers
#up this screen and will be disappear when i press the button
name: 'First_Screen'
BoxLayout:
orientation: 'horizontal'
spacing: 50
padding: [50, 50, 50, 50]
canvas:
Rectangle:
pos: self.pos
size: self.size
source: 'image/background.jpg'
Button:
id: campustown
width: 40
pos_hint: {'x' : 0, 'y':.45}
size_hint: [.6,.1]
background_normal:'image/test.png'
background_down:'image/test2.png'
border: (0,0,0,0)
font_size: 15
text: 'campus-town'
这两张图片展示了我想要完成的事情:
我该怎么做?
Python代码
- 从
class First_Screen()
中删除
BoxLayout
片段 - Py
class First_Screen(Screen):
pass
kv 文件
- 为按钮添加一个
on_release
事件 - 将
background_normal
设置为background_down
片段-kv
<First_Screen>:
name: 'First_Screen'
Button:
id: campustown
background_normal: 'image/test.png'
background_down: 'image/test2.png'
border: (0,0,0,0)
font_size: 15
text: 'campus-town'
on_release:
self.background_normal = self.background_down