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

2024-10-05 14:25:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道如何创建一个通知程序,可以存储一个以上的时间和用户从一个小图形用户界面输入的注释。这是我使用的最基本的代码:

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()

“inputer”是接收用户输入的文件。例如,如果我想在同一天得到2个提醒。我该如何编写代码?因为现在日期和时间的变量是固定的,不能在某个时间存储更多的信息。你知道吗

我是一个新的编码抱歉,如果这个问题似乎愚蠢的xd (使用python btw)


Tags: the代码用户fromimport程序datetimetkinter
1条回答
网友
1楼 · 发布于 2024-10-05 14:25:21

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

列表

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

相关问题 更多 >