Python Kivy:返回用于其他函数的值
我的python文件: 类主屏幕(屏幕): ampm=ObjectProperty(无) 周末=对象属性(无) 我的文件: : 名称:“主屏幕” 输入:root.starttimer() 小时:小时 分钟:分钟 第二:第二 周末:周末结束 上午/下午 报警列表:报警列表Python Kivy:返回用于其他函数的值,python,kivy,Python,Kivy,我的python文件: 类主屏幕(屏幕): ampm=ObjectProperty(无) 周末=对象属性(无) 我的文件: : 名称:“主屏幕” 输入:root.starttimer() 小时:小时 分钟:分钟 第二:第二 周末:周末结束 上午/下午 报警列表:报警列表 BoxLayout: orientation: "vertical" size_hint: (1, 1) BoxLayout: orientation: "horizontal"
BoxLayout:
orientation: "vertical"
size_hint: (1, 1)
BoxLayout:
orientation: "horizontal"
size_hint: (1, .833)
#width: 800
#height: 400
BoxLayout:
orientation: "vertical"
size_hint: (.5, 1)
LabelB:
text: "Alarm Times"
size_hint: (1, .1)
bcolor: 0,0,1,1
ListView:
id: alarm_list
size_hint: (1, .6)
adapter:
ListAdapter(data=[], cls=main.AlarmListButton)
BoxLayout:
id: user_input_section
orientation: "horizontal"
size_hint: (1, .1)
LabelB:
text: "Hour"
bcolor: 0,0,1,1
TextInput:
id: hour
LabelB:
text: "Minute"
bcolor: 0,0,1,1
TextInput:
id: minute
LabelB:
text: "Second"
bcolor: 0,0,1,1
TextInput:
id: second
BoxLayout:
orientation: "horizontal"
size_hint: (1, .1)
LabelB:
text:
size_hint: (.25, 1)
bcolor: 0,0,1,1
Switch:
id: am_pm
on_active: root.switch_ampm_clicked(self, self.active)
size_hint: (.25, 1)
LabelB:
text:
size_hint: (.25, 1)
bcolor: 0,0,1,1
Switch:
id: week_end
on_active: root.switch_weekend_clicked(self, self.active)
size_hint: (.25, 1)
我的结果:
07:00:00 <kivy.uix.switch.Switch object at 0x0A1AAE68> <kivy.uix.switch.Switch object at 0x0A1B47A0>
07:00:00
我不知道如何获取ampm或weekend的值,以便将其存储在数据库中
我已经按照答案做了,但我得到了同样的精确结果
我只包含了部分代码。问题
什么?您可以编辑您知道的问题。目前没有对该问题进行编辑。我已找到如何编辑原始问题,并使其正确显示,并删除了我的评论。抱歉,我是stackoverflow新手,没有意识到我必须将其格式化为代码才能正确显示。我希望这有帮助。
07:00:00 <kivy.uix.switch.Switch object at 0x0A1AAE68> <kivy.uix.switch.Switch object at 0x0A1B47A0>
class MainScreen(Screen):
ampm = StringProperty("")
weekend = StringProperty("")
def switch_ampm_clicked(self, switch, value):
print("ampm args = " + str(value))
if switch.active: # if True
self.ampm = "PM"
else:
self.ampm = "AM"
print(self.ampm)
def switch_weekend_clicked(self, switch, value):
print("weekend args = " + str(value))
if switch.active:
self.weekend = "Weekend"
else:
self.weekend = "Weekday"
print(self.weekend)