存储来自用户输入的多个输入

时间:2018-09-23 21:20:46

标签: python tkinter

我想知道我如何创建一个通知器,该通知器可以存储1次以上的时间,并通过一个小gui记录用户输入的注释。这段代码是我正在使用的最基本的代码:

from datetime import datetime
from threading import Timer
from tkinter import messagebox
from tkinter import *
from inputer import *


x = datetime.today()
y = x.replace(day=q, hour=w, minute=e, second=0, microsecond=0)

delta_t = y - x

secs = delta_t.seconds+1

def Note():
    # in this function i put the commands to open 
    # a small window with the reminder/note
    print("hello world")
    #...

t = Timer(secs, Note)
t.start()

“输入程序”是接受用户输入的文件。例如,如果我想在同一天收到2条提醒。我该如何编码?因为现在日期和时间变量是固定的,并且无法存储在特定时间使用的更多信息。

如果这个问题看起来很愚蠢,我对编码非常陌生xd (使用python btw)

1 个答案:

答案 0 :(得分:0)

澄清后,我认为这是最好的,您可以将多个时间戳存储在列表或字典中

列表

timestamps = []
timestamp_1 = '1h1m1s' # these variables can be assigned with input() as well
timestamp_2 = '2h2m2s'

timestamps.append(timestamp_1)
timestamps.append(timestamp_2)

print(timestamps[0])
print(timestamps[1])
chrx@chrx:~/python/stackoverflow/9.23$ python3.7 loop.py 
1h1m1s
2h2m2s

字典

timestamps = {}
timestamp_3 = '3h3m3s'
timestamp_4 = '4h4m4s'

timestamps['ts_3'] = timestamp_3
timestamps['ts_4'] = timestamp_4

print(timestamps['ts_3'])
print(timestamps['ts_4'])
3h3m3s
4h4m4s