I have a tkinker window with date
and choose date
button which i call it as a home page. When the user choose the date, I want the date to be updated in the Home Page. I retuned the selected date in the datecheck
function. Then i want to update the homepage date with returned date. I don't know how to make it possible. Help me with some solution.
Here's the Sample Code I wrote:
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()
Screenshot: