Python 缺少1个必需的位置参数:';自我';在基维
我无法从bon()函数运行suite()函数,当我尝试运行它时,它返回以下错误Python 缺少1个必需的位置参数:';自我';在基维,python,python-3.x,kivy,kivy-language,Python,Python 3.x,Kivy,Kivy Language,我无法从bon()函数运行suite()函数,当我尝试运行它时,它返回以下错误缺少1个必需的位置参数:“self” ( 我想这是因为我调用了错误的函数,但我尝试了其他方法,每次我都有这个错误,在我的程序中,我不能在类屏幕管理器中移动bon()函数,怎么做plz 这是我的密码: import kivy from kivy.app import App from kivy.clock import Clock from kivy.uix.button import Button from kivy.
缺少1个必需的位置参数:“self”
(
我想这是因为我调用了错误的函数,但我尝试了其他方法,每次我都有这个错误,在我的程序中,我不能在类屏幕管理器中移动bon()函数,怎么做plz
这是我的密码:
import kivy
from kivy.app import App
from kivy.clock import Clock
from kivy.uix.button import Button
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import StringProperty, BooleanProperty, NumericProperty
kivy.uix.screenmanager.FadeTransition
kv = """
#: import NoTransition kivy.uix.screenmanager.NoTransition
#:import Clock kivy.clock.Clock
#: import FadeTransition kivy.uix.screenmanager.FadeTransition
#: import RiseInTransition kivy.uix.screenmanager.RiseInTransition
#: import CardTransition kivy.uix.screenmanager.CardTransition
MyScreenManager:
transition: RiseInTransition()
Question1:
name: "question1"
Question2:
name: "question2"
<Question1>:
label_wid : ratio
FloatLayout:
Button:
text: "+1"
pos: 270, 300
size_hint: .30, .10
background_color: 0,1,0,0.75
on_press:
root.mauvais()
Button:
text: "following"
pos: 270, 240
size_hint: .30, .10
background_color: 0,1,0,0.75
on_press:
Clock.schedule_once(root.manager.suite, 0.75)
Label:
id: ratio
text: root.manager.theText
pos: 280,270
font_size: 17
color: 0,0,1,0.65
<Question2>:
"""
class MyScreenManager(ScreenManager):
theText = StringProperty('')
m = BooleanProperty(True)
u = BooleanProperty(True)
t = NumericProperty(0)
def suite(root,text,self):
self.m=True
root.current = "question2"
class Question1(Screen):
def mauvais(self):
if self.manager.m==True:
self.manager.t += 1
self.manager.theText = str(self.manager.t)
self.manager.m=False
def bon(self, root):
if self.manager.u==True:
self.manager.t = "bon"
self.manager.theText = str(self.manager.t)
self.manager.u=False
Clock.schedule_once(root.manager.suite, 0.75)
pass
class Question2(Screen):
pass
class Quizz(App):
def build(self):
self.title = 'Quizz'
Window.clearcolor = (0, 1, 1, 0.25)
return Builder.load_string(kv)
if __name__ == '__main__':
Quizz().run()
导入kivy
从kivy.app导入应用程序
从kivy.clock导入时钟
从kivy.uix.button导入按钮
从kivy.core.window导入窗口
从kivy.lang导入生成器
从kivy.uix.screenmanager导入screenmanager,屏幕
从kivy.properties导入StringProperty、BooleanProperty、NumericProperty
kivy.uix.screenmanager.FadeTransition
kv=”“”
#:导入NotTransition kivy.uix.screenmanager.NotTransition
#:导入Clock kivy.Clock.Clock
#:导入FadeTransition kivy.uix.screenmanager.FadeTransition
#:导入RiseInTransition kivy.uix.screenmanager.RiseInTransition
#:导入CardTransition kivy.uix.screenmanager.CardTransition
MyScreenManager:
转换:RiseInTransition()
问题1:
姓名:“问题1”
问题2:
姓名:“问题2”
:
标签宽度:比率
浮动布局:
按钮:
案文:“+1”
位置:270300
大小提示:.30,.10
背景颜色:0,1,0,0.75
新闻界:
root.mauvais()
按钮:
案文:“以下”
位置:270240
大小提示:.30,.10
背景颜色:0,1,0,0.75
新闻界:
Clock.schedule_一次(root.manager.suite,0.75)
标签:
id:比率
text:root.manager.theText
位置:280270
字体大小:17
颜色:0,0,1,0.65
:
"""
类MyScreenManager(屏幕管理器):
theText=StringProperty(“”)
m=布尔属性(真)
u=布尔属性(真)
t=数值属性(0)
def套件(根目录、文本、自身):
self.m=True
root.current=“问题2”
课堂问题1(屏幕):
def mauvais(自我):
如果self.manager.m==True:
self.manager.t+=1
self.manager.theText=str(self.manager.t)
self.manager.m=False
def bon(self,root):
如果self.manager.u==True:
self.manager.t=“bon”
self.manager.theText=str(self.manager.t)
self.manager.u=False
Clock.schedule_一次(root.manager.suite,0.75)
通过
课堂问题2(屏幕):
通过
课堂测验(应用程序):
def生成(自):
self.title='Quizz'
Window.clearcolor=(0,1,1,0.25)
返回生成器。加载字符串(kv)
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
Quizz().run()
您需要先将self
放在suite
函数中,然后将root
放在root.current=“question2”
行中,并删除MyScreenManager
类中的current
属性。因此,suite()
应如下所示:
def suite(self, root):
self.m=True
#root.current = "question2"