Every week has a number of the year ( 00,01,02,03 ... 53 ). On Click of a button, if the week number is odd then output should be No and it is Yes if week number is even.
We used int() to convert string to number.
Check the formatted output when we use strftime(). Here we used %U to get the week number as string.
import tkinter as tk
from datetime import date
my_w = tk.Tk()
my_w.geometry("350x300") # change width height
def my_upd():
dt=date.today().strftime('%U') # week number as string
if(int(dt)%2==0):
str1="Yes" # for even week number
else:
str1="No" # for odd week number
l1.config(text=str1) # update the text on label
b1=tk.Button(my_w,text='Click me',command=lambda:my_upd())
b1.grid(row=1,column=1,padx=60,pady=30)
l1=tk.Label(my_w,text='Data')
l1.grid(row=1,column=2)
my_w.mainloop()
Updating width option of a Tkinter button by connecting to a Spinbox value by using config()
import tkinter as tk
from tkinter import *
my_w = tk.Tk()
my_w.geometry("450x300") # Size of the window, width & height
my_w.title("www.plus2net.com")
# Creating list from a range with start , stop and step values
my_list = list(range(10, 30, 2))
t2 = tk.IntVar() # to store the selected value of the Spinbox
sb2 = Spinbox(
my_w, values=my_list, width=4, textvariable=t2, font=18, command=lambda: my_upd()
)
sb2.grid(row=0, column=0, padx=20, pady=60)
b1 = tk.Button(my_w, text="Demo", font=16, width=10, bg="yellow")
b1.grid(row=0, column=1, pady=60)
def my_upd(): # Update the width of the button
b1.config(width=t2.get())
my_w.mainloop() # Keep the window open