Python 如何更改kivy中另一类标签的行为
我想创建一个页面,显示一个表单和一个提交按钮,当点击它时,它将带您到另一个页面,该页面将显示从表单页面输入的数据 我创建了两个类表单和配置文件,但当我单击表单按钮时,它将带您进入配置文件页面,但没有任何更改 我尝试过很多事情,但都做不到,请帮忙 .py文件Python 如何更改kivy中另一类标签的行为,python,kivy,Python,Kivy,我想创建一个页面,显示一个表单和一个提交按钮,当点击它时,它将带您到另一个页面,该页面将显示从表单页面输入的数据 我创建了两个类表单和配置文件,但当我单击表单按钮时,它将带您进入配置文件页面,但没有任何更改 我尝试过很多事情,但都做不到,请帮忙 .py文件 from kivy.app import App from kivy.uix.boxlayout import BoxLayout from kivy.properties import ObjectProperty from kivy.ui
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
from kivy.uix.widget import Widget
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
class Manager(ScreenManager):
pass
class Profile(Screen):
profile_name = ObjectProperty()
profile_matric = ObjectProperty()
profile_school = ObjectProperty()
profile_programme = ObjectProperty()
profile_level = ObjectProperty()
def make_changes(self):
self.ids.profile_name = 'New name'
class Form(Screen):
user_name = ObjectProperty()
matric = ObjectProperty()
school = ObjectProperty()
programme = ObjectProperty()
level = ObjectProperty()
def submit(self):
y = Profile()
y.make_changes()
kv = Builder.load_file('main.kv')
class SpinApp(App):
def build(self):
return kv
if __name__ == '__main__':
SpinApp().run()
Manager:
Form:
Profile:
<Form@BoxLayout>:
name: 'form'
orientation: 'vertical'
user_name: user_name
matric: matric
school: school
programme: programme
level: level
RelativeLayout:
GridLayout:
cols: 1
#size_hint: (0.8, 0.8)
spacing: 5
padding: [20]
pos_hint: {'center_x':.5, 'center_y':.5}
background_normal: ''
GridLayout:
cols: 2
Label:
text: '\nName'
size_hint_x: None
size: self.texture_size
pos_hint: {'left': 1}
bold: True
size_hint_y: None
height: 80
Input_text:
id: user_name
hint_text: 'enter your full name'
GridLayout:
cols: 2
Input_label:
text: '\nMatric Number'
Input_text:
id: matric
hint_text: 'eg. se/mat-csc/19/0000'
GridLayout:
cols: 2
Input_label:
text: '\nSchool'
Input_text:
id: school
hint_text: 'your school'
GridLayout:
cols: 2
Input_label:
text: '\nLevel'
Input_text:
id: level
hint_text: 'Enter your level'
GridLayout:
cols: 2
Input_label:
text: '\nProgramme'
Input_text:
id: programme
hint_text: 'type your programme'
Button:
text: 'submit'
on_release:
app.root.current = 'profile'
root.submit()
<Profile@BoxLayout>:
name: 'profile'
orientation: 'vertical'
profile_name: profile_name
profile_matric: profile_matric
profile_level: profile_level
profile_school: profile_school
profile_programme: profile_programme
RelativeLayout:
GridLayout:
cols: 1
size_hint: (0.8, 0.8)
spacing: 5
padding: [20]
pos_hint: {'center_x':.5, 'center_y':.5}
background_normal: ''
canvas.before:
Color:
rgba: (253/255, 245/255, 230/255, 1)
RoundedRectangle:
size: self.size
pos: self.pos
radius: [15]
Image:
source: 'slde_1.png'
size: self.texture_size
profile_label:
id: profile_name
text: 'Name: '
profile_label:
id: profile_matric
text: 'Matric no.:'
profile_label:
id: profile_level
text: 'Level:'
profile_label:
id: profile_school
text: 'School:'
profile_label:
id: profile_programme
text: 'Programme:'
<profile_label@Label>:
color: 1,1,1,1
bold: True
font_size: 30
size_hint_y: None
height: 85
text_size: self.size
halign: 'left'
valign: 'middle'
padding: [10,0]
canvas.before:
Color:
rgba: 47/255, 79/255, 79/255, 1
RoundedRectangle:
size: self.size
pos: self.pos
radius: [25]
<Input_label@Label>:
size_hint_x: None
size: self.texture_size
pos_hint: {'left': 1,}
size_hint_y: None
height: 80
bold: True
<Input_text@TextInput>:
multiline: False
size_hint_y: None
height: 80
padding: [10,20]
background_normal: ''
background_color: 240/255, 248/255, 1, 1
valign: 'bottom'
.kv文件
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
from kivy.uix.widget import Widget
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
class Manager(ScreenManager):
pass
class Profile(Screen):
profile_name = ObjectProperty()
profile_matric = ObjectProperty()
profile_school = ObjectProperty()
profile_programme = ObjectProperty()
profile_level = ObjectProperty()
def make_changes(self):
self.ids.profile_name = 'New name'
class Form(Screen):
user_name = ObjectProperty()
matric = ObjectProperty()
school = ObjectProperty()
programme = ObjectProperty()
level = ObjectProperty()
def submit(self):
y = Profile()
y.make_changes()
kv = Builder.load_file('main.kv')
class SpinApp(App):
def build(self):
return kv
if __name__ == '__main__':
SpinApp().run()
Manager:
Form:
Profile:
<Form@BoxLayout>:
name: 'form'
orientation: 'vertical'
user_name: user_name
matric: matric
school: school
programme: programme
level: level
RelativeLayout:
GridLayout:
cols: 1
#size_hint: (0.8, 0.8)
spacing: 5
padding: [20]
pos_hint: {'center_x':.5, 'center_y':.5}
background_normal: ''
GridLayout:
cols: 2
Label:
text: '\nName'
size_hint_x: None
size: self.texture_size
pos_hint: {'left': 1}
bold: True
size_hint_y: None
height: 80
Input_text:
id: user_name
hint_text: 'enter your full name'
GridLayout:
cols: 2
Input_label:
text: '\nMatric Number'
Input_text:
id: matric
hint_text: 'eg. se/mat-csc/19/0000'
GridLayout:
cols: 2
Input_label:
text: '\nSchool'
Input_text:
id: school
hint_text: 'your school'
GridLayout:
cols: 2
Input_label:
text: '\nLevel'
Input_text:
id: level
hint_text: 'Enter your level'
GridLayout:
cols: 2
Input_label:
text: '\nProgramme'
Input_text:
id: programme
hint_text: 'type your programme'
Button:
text: 'submit'
on_release:
app.root.current = 'profile'
root.submit()
<Profile@BoxLayout>:
name: 'profile'
orientation: 'vertical'
profile_name: profile_name
profile_matric: profile_matric
profile_level: profile_level
profile_school: profile_school
profile_programme: profile_programme
RelativeLayout:
GridLayout:
cols: 1
size_hint: (0.8, 0.8)
spacing: 5
padding: [20]
pos_hint: {'center_x':.5, 'center_y':.5}
background_normal: ''
canvas.before:
Color:
rgba: (253/255, 245/255, 230/255, 1)
RoundedRectangle:
size: self.size
pos: self.pos
radius: [15]
Image:
source: 'slde_1.png'
size: self.texture_size
profile_label:
id: profile_name
text: 'Name: '
profile_label:
id: profile_matric
text: 'Matric no.:'
profile_label:
id: profile_level
text: 'Level:'
profile_label:
id: profile_school
text: 'School:'
profile_label:
id: profile_programme
text: 'Programme:'
<profile_label@Label>:
color: 1,1,1,1
bold: True
font_size: 30
size_hint_y: None
height: 85
text_size: self.size
halign: 'left'
valign: 'middle'
padding: [10,0]
canvas.before:
Color:
rgba: 47/255, 79/255, 79/255, 1
RoundedRectangle:
size: self.size
pos: self.pos
radius: [25]
<Input_label@Label>:
size_hint_x: None
size: self.texture_size
pos_hint: {'left': 1,}
size_hint_y: None
height: 80
bold: True
<Input_text@TextInput>:
multiline: False
size_hint_y: None
height: 80
padding: [10,20]
background_normal: ''
background_color: 240/255, 248/255, 1, 1
valign: 'bottom'
管理器:
表格:
轮廓:
:
名称:“表格”
方向:“垂直”
用户名:用户名
矩阵的
学校:学校
节目:节目
级别:级别
相对长度:
网格布局:
科尔斯:1
#尺寸提示:(0.8,0.8)
间距:5
填充:[20]
位置提示:{'center_x':.5'center_y':.5}
背景\u正常:“”
网格布局:
科尔斯:2
标签:
文本:'\n名称'
大小提示:无
大小:self.texture\u大小
位置提示:{'left':1}
黑体字:对
尺寸提示:无
身高:80
输入文本:
id:用户名
提示文字:“输入您的全名”
网格布局:
科尔斯:2
输入标签:
文本:'\n地图编号'
输入文本:
id:matric
提示文字:“如se/mat csc/19/0000”
网格布局:
科尔斯:2
输入标签:
文本:'\n学校'
输入文本:
id:学校
提示文字:“你的学校”
网格布局:
科尔斯:2
输入标签:
文本:'\n级别'
输入文本:
id:级别
提示文字:“输入你的等级”
网格布局:
科尔斯:2
输入标签:
文本:'\n程序'
输入文本:
id:计划
提示文字:“键入您的程序”
按钮:
文本:“提交”
发布时:
app.root.current='profile'
root.submit()
:
名称:“个人资料”
方向:“垂直”
配置文件\名称:配置文件\名称
轮廓矩阵:轮廓矩阵
配置文件\级别:配置文件\级别
学校简介:学校简介
简介课程:简介课程
相对长度:
网格布局:
科尔斯:1
尺寸提示:(0.8,0.8)
间距:5
填充:[20]
位置提示:{'center_x':.5'center_y':.5}
背景\u正常:“”
在以下情况之前:
颜色:
rgba:(253/255、245/255、230/255、1)
圆反射角:
大小:self.size
pos:self.pos
半径:[15]
图片:
资料来源:“slde_1.png”
大小:self.texture\u大小
配置文件标签:
id:profile\u名称
文本:“名称:”
配置文件标签:
id:profile_matric
正文:“矩阵编号:”
配置文件标签:
id:profile_级别
文本:“级别:”
配置文件标签:
id:profile_学校
课文:“学校:”
配置文件标签:
id:profile_计划
案文:“方案:”
:
颜色:1,1,1,1
黑体字:对
字体大小:30
尺寸提示:无
身高:85
文本大小:self.size
哈利格:“左”
valign:“中间”
填充:[10,0]
在以下情况之前:
颜色:
rgba:47/255、79/255、79/255、1
圆反射角:
大小:self.size
pos:self.pos
半径:[25]
:
大小提示:无
大小:self.texture\u大小
位置提示:{'left':1,}
尺寸提示:无
身高:80
黑体字:对
:
多行:False
尺寸提示:无
身高:80
填充:[10,20]
背景\u正常:“”
背景颜色:240/255、248/255、1、1
valign:“底部”
在配置文件中
类中,您可以在enter()上添加
方法。每次输入配置文件
屏幕
时,都会执行on_enter()
方法。比如说:
class Profile(Screen):
profile_name = ObjectProperty()
profile_matric = ObjectProperty()
profile_school = ObjectProperty()
profile_programme = ObjectProperty()
profile_level = ObjectProperty()
def on_enter(self, *args):
form = self.manager.get_screen('form')
self.profile_name.text = form.user_name.text
self.profile_matric.text = form.matric.text
self.profile_school.text = form.school.text
self.profile_programme.text = form.programme.text
self.profile_level.text = form.level.text
然后在您的kv
中,submit
按钮
只需更改屏幕
:
Button:
text: 'submit'
on_release:
app.root.current = 'profile'
谢谢,正是我需要的真的很感激