'tkinter/datetime/weekday/dictionary/ type error : strptime() argument 1 must be str, not entry
In function (def wky(event)), without 'global ab', it happens next error message : 'UnboundLocalError'. And then, I used that words(global ab). But, I wonder that that words is necessary? Without declare the global in function, we can't use the local variable?
In function, is there wrong sentence? I used the Dictionary. I thought that the appropriate value is coming in Dictionary. But, when I run the below code, it happened the Error message. What I miss something?
In conclusion, this code is that label's value come from in ab variable. ab variable's initial value is None. User immediately input any value, and then label's value is automatically inserted following press 'Enter'key.
I hope for your merciful help ~ ^^
Below the paragrape, I wrote the code.
from tkinter import *
from datetime import datetime
root = Tk()
root.title("Moving")
root.geometry("640x480")
root.resizable(False, False)
def wky(event):
global ab
ab = datetime.strptime(ab, "%Y-%m-%d")
dateDict = {0:"Mon", 1:"Tue", 2:"Wed", 3:"Thu", 4:"Fri", 5:"Sat", 6:"Sun"}
dateDict[ab.weekday()]
label.config(text = dateDict[ab.weekday()])
ab = Entry(root)
ab.bind("<Return>", wky)
ab.pack()
label=Label(root)
label.pack()
root.mainloop()
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\tkinter\__init__.py", line 1921, in __call__return self.func(*args)
File "c:\Users\JS\Desktop\PYTHONWORKSPACE\movingproject\1_name.py", line 145, in wky
ab = datetime.strptime(ab, "%Y-%m-%d")
TypeError: strptime() argument 1 must be str, not Entry
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
