python创建数据表_python – 创建一个表单来填充Kivy中的数据库

最终目标是使用各种小部件(textinput,复选框等)在表单中创建包含表单信息的条目.我想在表单的末尾创建一个按钮来提交对dict的响应,但是我被卡住了.我能想到实现这一目标的唯一方法是将所有id都设置为对象属性,然后在一个函数中单独引用它们,如series1.value … series2.value …

这看起来非常麻烦,以后很难在表单中添加更多条目.

这是我的.py:

from kivy.app import App

from kivy.uix.gridlayout import GridLayout

from kivy.uix.boxlayout import BoxLayout

from kivy.properties import ObjectProperty

from kivy.uix.checkbox import CheckBox

from kivy.uix.togglebutton import ToggleButton

from kivy.uix.button import Button

class DermRoot(BoxLayout):

dict_filled_from_form = {}

def add_entry_to_db(self,dict_filled_from_form):

pass

class DemographForm(BoxLayout):

sex = ObjectProperty()

age_input = ObjectProperty()

def add_entry(self,dict_of_form):

dict_filled_from_form = dict_of_form

#is this possible?

#or do I have to do dict_filled_from_form['series1'] = series1.value etc

class DermApp(App):

pass

if __name__ == '__main__':

DermApp().run()

和我的kv文件

DermRoot:

:

DemographForm

:

orientation: "vertical"

GridLayout:

age_input: age_input

sex: sex

cols: 2

Label:

text: "Patient's Age:"

TextInput:

id: age_input

focus: series4

multiline: False

Label:

text: "Sex:"

ToggleButton:

id: sex

text: "Male" if self.state == 'normal' else "Female"

Label:

text: "Standard Series to Include?"

GridLayout:

series1: series1

series2: series2

series3: series3

series4: series4

series5: series5

cols: 2

CheckBox:

id: series1

Label:

text: "Series1"

CheckBox:

id: series2

Label:

text: "Series2"

CheckBox:

id: series3

Label:

text: "series"

CheckBox:

id: series4

Label:

text: "series4"

CheckBox:

id: series5

Label:

text: "Series 5"

Button:

height: "40dp"

size_hint_y: None

text: "Add Entry to Database"

on_press: root.add_entry(dict_of_form = 'how do I get this?')

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值