我想生成一个计数,如果某个事件发生而我没有得到它,它会将计数器加1。其思想是,当将其中一个正确的图像(Dropable_zone_Object:[to_box,])拖放到正确的位置时,计数器应添加+1。目前,该应用程序工作正常,但在打印计数器时,其值始终为1。我应该换什么
Arrastar.kv
#:kivy 1.9.0
<Relaciona3x2>:
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: 'data/img/fondobosque.jpg'
BoxLayout:
orientation: 'vertical'
BoxLayout:
id: from_box
Widget:
DragableButton:
canvas:
Rectangle:
pos: self.pos
size: self.size
source: 'data/img/letra_i/iglu.png'
bound_zone_objects: [from_box, to_box ]
droppable_zone_objects: [to_box, ]
drop_func: app.greet
Widget:
DragableButton:
canvas:
Rectangle:
pos: self.pos
size: self.size
source: 'data/img/letra_i/indio.png'
bound_zone_objects: [from_box, to_box, ]
droppable_zone_objects: [to_box, ]
drop_func: app.greet
Widget:
DragableButton:
canvas:
Rectangle:
pos: self.pos
size: self.size
source: 'data/img/letra_m/moto.png'
bound_zone_objects: [from_box, to_box, ]
#droppable_zone_objects: [to_box, ]
drop_func: app.greet
Widget:
BoxLayout:
id: from_box
Widget:
DragableButton:
canvas:
Rectangle:
pos: self.pos
size: self.size
source: 'data/img/letra_u/una.png'
bound_zone_objects: [from_box, to_box, ]
#droppable_zone_objects: [to_box, ]
drop_func: app.greet
Widget:
DragableButton:
canvas:
Rectangle:
pos: self.pos
size: self.size
source: 'data/img/letra_i/iman_1.png'
bound_zone_objects: [from_box, to_box, ]
droppable_zone_objects: [to_box, ]
drop_func: app.greet
Widget:
DragableButton:
canvas:
Rectangle:
pos: self.pos
size: self.size
source: 'data/img/letra_u/urraca.png'
bound_zone_objects: [from_box, to_box, ]
#droppable_zone_objects: [to_box, ]
drop_func: app.greet
Widget:
Image:
id: to_box
source: "data/img/caldero.png"
<Relaciona4x2>:
AnchorLayout:
Image:
source: "data/img/fondobosque.jpg"
allow_stretch: True
keep_ratio: False
<Relaciona5x2>:
AnchorLayout:
Image:
source: "data/img/fondobosque.jpg"
allow_stretch: True
keep_ratio: False
阿拉斯特拉比
__all__ = ('Relaciona3x2', 'Relaciona4x2', 'Relaciona5x2')
import kivy
kivy.require('1.0.6')
from DragableButton import DragableButton
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.core.window import Window
Builder.load_file('arrastrar.kv')
class Contador(object):
def __init__(self, inicial=0):
self.numero = inicial
def next(self):
self.numero += 1
return self.numero
class Relaciona3x2(Screen):
pass
class Relaciona4x2(Screen):
pass
class Relaciona5x2(Screen):
pass
class ArrastraApp(App):
def build(self):
#Window.fullscreen = 'auto'
return Relaciona3x2()
def greet(self):
cuenta = Contador()
print('Draggin done!')
if DragableButton.droppable_zone_objects is True:
print(cuenta.next())
if __name__ == "__main__":
ArrastraApp().run()
我还是无法进入下一个屏幕,约翰。我已经在ScreenManager中设置了计数器和If,但是我仍然无法从一个页面转到另一个页面,关于ScreenManager的操作有些我不知道
Arrastar.kv
阿拉斯特拉比
谢谢John,计数器已经做了正确的求和,但是现在当我尝试在计数器达到3时转到下一个屏幕时,它什么也不做
在对
greet()
的每次调用中,您都在创建一个新的Contador
实例。您可能应该只创建一个Contador
实例,如下所示:相关问题 更多 >
编程相关推荐