Python Forum
Issue with 'if' and datetime
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue with 'if' and datetime
#1
I'd like my gui to have a different background based on the current hour and month. I've imported datetime. Its not returning any errors but returns the else statement.

second_now = datetime.datetime.now().second
minute_now = datetime.datetime.now().minute
hour_now = datetime.datetime.now().hour

day_now = datetime.datetime.now().day
month_now = datetime.datetime.now().month
year_now = datetime.datetime.now().year

if hour_now >= 7 <= 21 and month_now >= 5 <= 9:
    background = PhotoImage(file="C:\\Users\\blake\\PycharmProjects\\farming\\images\\farm_summer_day.png")
    background_label = Label(root, image=background)
    background_label.place(x=0, y=0, relwidth=1, relheight=1)
else:
    print("")
Reply


Messages In This Thread
Issue with 'if' and datetime - by blakefindlay - Feb-07-2021, 11:31 PM
RE: Issue with 'if' and datetime - by bowlofred - Feb-08-2021, 12:22 AM
RE: Issue with 'if' and datetime - by blakefindlay - Feb-08-2021, 12:33 AM
RE: Issue with 'if' and datetime - by bowlofred - Feb-08-2021, 12:41 AM
RE: Issue with 'if' and datetime - by deanhystad - Feb-08-2021, 01:04 AM
RE: Issue with 'if' and datetime - by blakefindlay - Feb-08-2021, 01:44 AM
RE: Issue with 'if' and datetime - by deanhystad - Feb-08-2021, 02:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Datetime format issue with z sks3286 2 7,498 Apr-07-2020, 12:26 PM
Last Post: sks3286
  TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'str' findbikash 2 9,708 Sep-18-2019, 08:32 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020