I'm trying to create an app that opens a window with a calendar and then after the calendar window is close it will countdown until the selected date and time, while displaying the countdown timer. When I try to change the text of a label so I can display the countdown in the label I get the error "name 'lblstatus' is not defined".
Here's the code;
-------------------------------
Here's the code;
-------------------------------
import tkinter as tk from tkinter import ttk from tkinter import * from tkcalendar import * import datetime import time class Window(tk.Toplevel): def __init__(self, parent): super().__init__(parent) self.geometry('600x400+550+450') self.title('Select Date for sample insertion') # Add the Calendar module now = datetime.datetime.now() cal = Calendar(self, selectmode = 'day', year = int(now.strftime("%Y")), month = int(now.strftime("%m")), day = int(now.strftime("%d"))) cal.place(x=1, y=111) cal.pack(pady = 20, fill="both", expand=True) def dwcmd(): global status status = "Status=OK" caldate = cal.get_date()# + "18:45:00.000" a,b,c = caldate.split('/') m = int(min.get()) h = int(hr.get()) mytime =datetime.datetime(int(c)+2000, int(a), int(b), h, m, 0) timenow = datetime.datetime.now() print ("Time now: ", timenow) print ("mytime: ", mytime) while datetime.datetime.now() < mytime: print ("Waiting...", datetime.datetime.now()) time.sleep(10) print ("Time's up!") print (status) def dw2(): print ("ok") lblhour = tk.Label(self, text='Hour') lblhour.place(x=228,y=237) # Spinbox current_value = tk.StringVar(value=0) hr = tk.Spinbox( self, from_=0, to=23, width=5, #height=10, font =50, textvariable=current_value, state="readonly", wrap=True) lblmin = tk.Label(self, text='Minute') lblmin.place(x=214,y=260) # #label2.pack(ipadx=10, ipady=10) hr.pack() current_value = tk.StringVar(value=0) min = tk.Spinbox( self, from_=0, to=60, width=5, font =50, textvariable=current_value, state="readonly", wrap=True) min.pack() ttk.Button(self, text='Countdown', command=dwcmd).pack(expand=True), buttonclose = ttk.Button(self, text='Close', command=self.destroy).pack(expand=True) class App(tk.Tk): def __init__(self): super().__init__() self.geometry('600x400+550+450') self.title('MCL Water Boil') myvar = tk.StringVar() lblstatus = tk.Label(self, textvariable=myvar) lblstatus.place(x=277,y=238) myvar.set("not set") lblstatus.pack(pady=80) # place a button on the root window ttk.Button(self,text='Open Calendar', command=self.open_window).pack(expand=True) ttk.Button(self,text='Show status', command=self.dwcmd3).pack(expand=True) def dwcmd3(App): lblstatus.config(text="OK!") def open_window(self): window = Window(self) window.grab_set() if __name__ == "__main__": app = App() app.mainloop()
Larz60+ write Apr-19-2022, 07:23 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.