python - 如何在kivy中随时间变化功能?
问题描述
比如这里是我的代码:
from kivy.properties import ObjectProperty
from kivymd.uix.button import MDFlatButton
from kivymd.uix.picker import MDDatePicker
from kivymd.app import MDApp
from kivy.lang import Builder
from kivymd.uix.dialog import MDDialog
from kivy.core.window import Window
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.config import Config
Config.set('kivy', 'keyboard_mode', 'systemandmulti')
Window.size = (400, 600)
class Log_in(Screen, MDApp):
def dop(self):
username = self.ids["user"].text
password = self.ids["passw"].text
if username == "MD" and password == "kivy":
self.manager.current = "main"
else:
dial = MDDialog(text='Opps Wrong!', background_color=(0.3, 1, 1, 0.3), size_hint=(0.5, 0.5),
radius=[20, 7, 20, 7], buttons=[
MDFlatButton(
text="Ok", text_color=self.theme_cls.primary_color, on_release=lambda x: dial.dismiss()
), ], )
dial.open()
class Main(Screen, MDApp):
date_y = ObjectProperty()
def date_se(self):
y = self.date_y
try:
MDDatePicker(self.today_date, y.year, y.month, y.day).open()
except AttributeError:
MDDatePicker(self.today_date).open()
def today_date(self, date_obj):
self.today_date = date_obj
如您所见,有 2 的屏幕。
class WindowManager(ScreenManager):
pass
kv = Builder.load_file("Wolf.kv")
class Wolf(MDApp):
def build(self):
self.theme_cls.primary_palette = "Yellow"
self.theme_cls.primary_hue = "900"
self.theme_cls.theme_style = "Dark"
return kv
Wolf().run()
这是我的 kivy 文件(kv):
WindowManager:
Log_in:
Main:
<Log_in>:
name:"log"
FloatLayout:
orientation:"vertical"
canvas.before:
Color:
rgba:rgba('#f2991b')
Triangle:
points:[0,self.size[1],self.size[0],self.size[1],0,self.size[1]-(0.4 *self.size[1])]
Color:
rgba:rgba('#f2881b')
Triangle:
points:[0,self.size[1],self.size[0],self.size[1],self.size[0],self.size[1]-(0.4 *self.size[1])]
MDIconButton:
text:'Nxt'
icon:"account"
size_hint:0.15,0.15
pos_hint:{'x':0.43,'y':0.55}
MDTextField:
id: user
hint_text : "Enter your Name"
helper_text : "Have u forget it?"
helper_text_mode : "on_focus"
icon_right : "android"
size_hint_x :None
width : '300'
pos_hint:{'center_x':0.5,'center_y':0.5}
multiline : False
foreground_color:0,0,1,1
on_text_validate: app.on_text_validate_callback(self)
MDTextField:
id: passw
hint_text : "Enter your Password"
helper_text : "cAsE SeNsItIvE"
helper_text_mode : "on_focus"
icon_right : "key"
size_hint_x :None
width : '300'
pos_hint:{'center_x':0.5,'center_y':0.4}
multiline : False
password:True
MDRectangleFlatButton:
id:btn
text:"Log in"
pos_hint:{'center_x': 0.5, 'center_y': 0.3}
on_press:root.dop()
<Main>:
name:"main"
FloatLayout:
MDIconButton:
icon:"alarm"
text:"Hlo"
on_press:root.date_se()
size_hint:0.15,0.15
pos_hint:{'x':0.03,'y':0.8}
现在我面临的问题是,我希望 21 天后用户名应该自动更改为“RIOT”,密码自动更改为“zxcvbnm”。正如大多数防病毒软件中发生的那样,在某些日子后他们会要求提供许可证密钥。我只想免费试用我的应用程序 21 天。我认为时钟功能将与 if 语句一起使用,但如何使用?谢谢帮助:)
解决方案
基本答案是使用 Clock.schedule_once 来安排一个函数,该函数在您想要的时间延迟之后执行您想要的操作。
但是,除非您希望您的应用程序连续运行 21 天,否则您实际上需要做一些进一步的事情来存储您希望事情发生的时间,然后每次应用程序启动时安排您的函数在该时间运行。
推荐阅读
- sql - 在所有分区内搜索 - SQL
- python - Django collectstatic:是否可以访问 Django 项目之外的静态文件?
- php - 如何保存kartik可编辑yii2
- javascript - 使用 JavaScript 在浏览器控制台中调用 Firefox 的 :screenshot 辅助函数
- java - 如何在while循环中使用switch case将base 10转换为任何base?
- nativescript - 无法通过点击按钮在 android 上播放声音
- mysql - 使用 mysql 从所有数据库中获取所有表
- c++ - 为什么这只有一半回溯?
- python - x86-64 程序集 - 在堆栈上创建一个字符串或为 CreateFile 创建一个寄存器
- python - Python os.system grep 与 bash grep 的结果不同