我有一个带有date
和choose date
按钮的 tkinker 窗口,我将其称为主页。当用户选择日期时,我希望在主页中更新日期。我在函数中重新调整了选定的日期datecheck
。然后我想用返回日期更新主页日期。我不知道如何使它成为可能。帮我解决一些问题。
这是我写的示例代码:
from tkinter import *
from tkinter import ttk
from tkinter import scrolledtext
import time
import tkinter.messagebox
from datetime import datetime
import tkinter as tk
import sys
import os
from tkcalendar import Calendar, DateEntry
from datetime import date
import multiprocessing
def datecheck():
global date_string
root = Tk()
s = ttk.Style(root)
s.theme_use('clam')
def print_sel():
global date_string,timestamp
date_string =cal.selection_get()
date_string=date_string.strftime("%d-%b-%Y")
print("returned_date",date_string)
root.destroy()
today = date.today()
d = int(today.strftime("%d"))
m= int(today.strftime("%m"))
y =int(today.strftime("%Y"))
cal = Calendar(root,
font="Arial 14", selectmode='day',
cursor="hand1", day=d,month=m,year=y)
cal.pack(fill="both", expand=True)
ttk.Button(root, text="ok", command=print_sel).pack()
def homepage():
global date_string,timestamp
if date_string == "":
timestamp = datetime.now().strftime("%d-%b-%Y")
else:
timestamp = date_string
def close_window():
window.destroy()
window = Tk()
window.title("Status Uploader")
window.geometry('500x200')
Label(window,
text="Status Uploader",
fg="blue",
bg="yellow",
font="Verdana 10 bold").pack()
Label(window,
text="Date : {}".format(timestamp),
fg="red",
bg="yellow",
font="Verdana 10 bold").pack()
txt = scrolledtext.ScrolledText(window, width=60, height=9.5)
txt.pack()
button = Button(window, fg='white', bg='blue',
text="Choose Date", command=datecheck)
button.place(x=35, y=152)
button = Button(window, fg='white', bg='red',
text="Close", command=close_window)
button.place(x=405, y=152)
window.mainloop()
global date_string,timestamp
date_string = ""
homepage()
截屏: