Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Alarm Clock [tkinter]
#1
Hiya! I'm trying to make an alarm clock as homework however I keep getting this strange error:
Error:
Traceback (most recent call last): File "C:\Users\RPC-K\OneDrive\Documents\PY.LESSON FLIES\HOMEWORK15\IDK.py", line 43, in <module> label1 = root.Label(root, image=bg) File "C:\Program Files\Python311\Lib\tkinter\__init__.py", line 2410, in __getattr__ return getattr(self.tk, attr) AttributeError: '_tkinter.tkapp' object has no attribute 'Label'
My code used to work as intended but now a blank white tkinter window is all tat appears.
I tried requesting assistance from my teacher but she is just as confused as I am so she left me to it.
Here is my code:
# Import Required Library
from tkinter import *
import datetime
import time
import winsound
from threading import *
 
# Create Object
root = Tk()
 
# Set geometry
root.geometry("400x200")
 
# Use Threading
def Threading():
	t1=Thread(target=alarm)
	t1.start()
 
def alarm():
	# Infinite Loop
	while True:
		# Set Alarm 
		set_alarm_time = f"{hour.get()}:{minute.get()}:{second.get()}"
 
		# Wait for one seconds
		time.sleep(1)
 
		# Get current time
		current_time = datetime.datetime.now().strftime("%H:%M:%S")
		print(current_time,set_alarm_time)
 
		# Check whether set alarm is equal to current time or not
		if current_time == set_alarm_time:
			print("Time to Wake up")
			# Playing sound
			winsound.PlaySound("sound.wav",winsound.SND_ASYNC)

bg = PhotoImage(file = r"C:\Users\RPC-K\Downloads\giphy.gif")

# Set the label's background color to match your application's 

# Show image using label 
label1 = root.Label(root, image=bg) 
label1.place(x = 530, y = 300) 
  
# Add text 
label2 = root.Label(root, text="Welcome", 
               bg = "#88cffa") 
  
label2.pack(pady = 50) 
  
# Create Frame 
frame1 = root.Frame(root, bg="#88cffa") 
frame1.pack(pady = 20)

# Add Labels, Frame, Button, Optionmenus
Label(root,text="Khanam's Alarm Clock",font=("Wistful 90 bold"),fg="Light Blue").pack(pady=10)
root.wm_attributes("-transparentcolor", "white")

Label(root,text="Set Time",font=("Wistful 50 bold"),fg="Dark blue").pack()
root.wm_attributes("-transparentcolor", "white")

label_instance = Label(root)  # Create an instance of the Label class
label_instance.configure(bg=root.cget("bg"))  # Call configure on the instance
 
frame = Frame(root)
frame.pack()
 
hour = StringVar(root)
hours = ('00', '01', '02', '03', '04', '05', '06', '07',
		'08', '09', '10', '11', '12', '13', '14', '15',
		'16', '17', '18', '19', '20', '21', '22', '23', '24'
		)
hour.set(hours[0])
 
hrs = OptionMenu(frame, hour, *hours)
hrs.pack(side=LEFT)
 
minute = StringVar(root)
minutes = ('00', '01', '02', '03', '04', '05', '06', '07',
		'08', '09', '10', '11', '12', '13', '14', '15',
		'16', '17', '18', '19', '20', '21', '22', '23',
		'24', '25', '26', '27', '28', '29', '30', '31',
		'32', '33', '34', '35', '36', '37', '38', '39',
		'40', '41', '42', '43', '44', '45', '46', '47',
		'48', '49', '50', '51', '52', '53', '54', '55',
		'56', '57', '58', '59', '60')
minute.set(minutes[0])
 
mins = OptionMenu(frame, minute, *minutes)
mins.pack(side=LEFT)
 
second = StringVar(root)
seconds = ('00', '01', '02', '03', '04', '05', '06', '07',
		'08', '09', '10', '11', '12', '13', '14', '15',
		'16', '17', '18', '19', '20', '21', '22', '23',
		'24', '25', '26', '27', '28', '29', '30', '31',
		'32', '33', '34', '35', '36', '37', '38', '39',
		'40', '41', '42', '43', '44', '45', '46', '47',
		'48', '49', '50', '51', '52', '53', '54', '55',
		'56', '57', '58', '59', '60')
second.set(seconds[0])
 
secs = OptionMenu(frame, second, *seconds)
secs.pack(side=LEFT)
 
Button(root,text="Set Alarm",font=("Comfortaa 15"),command=Threading).pack(pady=20)

# Create a canvas widget
canvas=Canvas(root, width=1000, height=500)
canvas.configure(background='black')

canvas.pack()

# Create an oval or ball in the canvas widget
ball=canvas.create_oval(10,10,50,50, fill="lavender")

# Move the ball
xspeed=yspeed=10

def move_ball():
   global xspeed, yspeed

   canvas.move(ball, xspeed, yspeed)
   (leftpos, toppos, rightpos, bottompos)=canvas.coords(ball)
   if leftpos <=0 or rightpos>=700:
      xspeed=-xspeed

   if toppos <=0 or bottompos >=350:
      yspeed=-yspeed

   canvas.after(100, move_ball)

canvas.after(1000, move_ball)

bounce = Tk.Label(parent, image=background_image)
bounce.place(x=0, y=0, relwidth=1, relheight=1)

# Execute Tkinter
root.mainloop()
All help would be greatly appreciated! Thanks! - moon
JUST A FRIENDLY REMINDER, I AM INFACT A YOUNG CHILD SO PLEASE FORGIVE ME IF I LACK OF ANY KNOWLEDGE THAT MAY SEEM OBVIOUS...I AM STILL DEVELOPING MY SKILLS IN PYTHON - YOURS SINCERELY, Moon
😋
Reply


Messages In This Thread
Alarm Clock [tkinter] - by moon - Jul-30-2024, 04:15 PM
RE: Alarm Cloxk [tkinter] - by deanhystad - Jul-30-2024, 05:20 PM
RE: Alarm Clock [tkinter] - by moon - Aug-07-2024, 12:40 PM
RE: Alarm Clock [tkinter] - by deanhystad - Aug-07-2024, 02:14 PM
RE: Alarm Clock [tkinter] - by moon - Aug-07-2024, 02:49 PM
RE: Alarm Clock [tkinter] - by deanhystad - Aug-07-2024, 05:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Monitor Computer Internal Clock EdMcCauley 3 570 May-10-2025, 01:52 AM
Last Post: deanhystad
  World Clock syntax error OscarBoots 1 1,251 May-03-2024, 05:20 AM
Last Post: snippsat
  Alarm system with state, class, enum. Frankduc 0 2,027 May-04-2022, 01:26 PM
Last Post: Frankduc
  simulation of alarm system Frankduc 6 3,255 Apr-21-2022, 03:45 PM
Last Post: Frankduc
  Module 'time' has no attribute 'clock' Sophie 4 5,647 Jan-25-2022, 08:05 PM
Last Post: Sophie
  Clock\time calculation script Drone4four 3 2,879 Jan-21-2022, 03:44 PM
Last Post: ibreeden
  time.clock not functioning Oldman45 3 3,988 Apr-07-2021, 08:51 AM
Last Post: Oldman45
  Cannot use function with timer/clock theangryprogrammer 1 4,071 Jan-22-2019, 04:22 PM
Last Post: Larz60+
  Problem with 'Clock' functionality panoss 2 4,373 May-17-2017, 07:03 PM
Last Post: snippsat
  Problems with Interrupts/ callback functions in Python for an Alarm Clock project Henry1 1 5,836 Dec-16-2016, 10:17 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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