我正在尝试制作带有闹钟和天气的tkinter GUI。由于某些原因,我的闹钟无法正常工作。我从另一个人那里“借用”了该代码,由于某种原因,它可以在他/她的程序上工作,但不是我的。
我什么都没尝试,因为它对python和编码来说是非常新的。
import tkinter as tk
from tkinter import *
from tkinter.ttk import *
import os
import time
from time import strftime
from datetime import date
today = date.today()
HEIGHT = 500
WIDTH = 500
def test_function(entry):
label3 = tk.Label(lower_frame, bg='white',font=('Courier',15), text=entry, anchor='nw', justify='left', bd=4)
label3.place(relwidth=1, relheight=1)
root = tk.Tk()
def quit_function():
root.destroy()
def SubmitButton():
AlarmTime= alarm_entry.get()
CurrentTime= time.strftime("%H:%M")
while AlarmTime != CurrentTime:
CurrentTime = time.strftime("%H:%M")
time.sleep(1)
if AlarmTime == CurrentTime:
label3 = tk.Label(lower_frame, bg='white',font=('Courier',15), text="Perkele", anchor='nw', justify='left', bd=4)
canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH)
canvas.pack()
background_image = tk.PhotoImage(file='landscape.png')
bg_label = tk.Label(root, image=background_image)
bg_label.place(x=0, y=0, relwidth=1, relheight=1)
frame = tk.Frame(root, bg='#08AEF6', bd=5)
frame.place(relx=0.5, rely=0.125, relwidth=0.75, relheight=0.1, anchor='n')
entry = tk.Entry(frame, font=40)
entry.place(relwidth=0.65, relheight=1)
button = tk.Button(frame, font=40, text="Get Weather", bg='gray', fg='black', command=lambda: test_function(entry.get()))
button.place(relx=0.7, relwidth=0.3, relheight=1)
lower_frame = tk.Frame(root, bg='#08AEF6', bd=10)
lower_frame.place(relx=0.5, rely=0.25, relwidth=0.75, relheight=0.6, anchor='n')
up_frame = tk.Frame(root, bg='#08AEF6', bd=5)
up_frame.place(relx=0.675, rely=0, relwidth=0.4, relheight=0.1, anchor='n')
alarm_button = tk.Button(up_frame, text="Set alarm time", bg='gray', fg='black', font=40, command=SubmitButton)
alarm_button.place(relx=0.7, rely=0.5, relwidth=0.3, relheight=0.45)
label3 = tk.Label(lower_frame, bg='white')
label3.place(relwidth=1, relheight=1)
label = tk.Label(up_frame, bg='white')
label.place(relx=0, relwidth=0.695, relheight=0.5)
date1 = tk.Label(up_frame, bg='white', text=today, font=40)
date1.place(relx=0, rely=0.5, relwidth=0.695, relheight=0.5)
quit_frame = tk.Frame(root, bg='#08AEF6', bd=5)
quit_frame.place(relx=0, rely=0, relwidth=0.1, relheight=0.1)
quit_button = tk.Button(quit_frame, command=quit_function, text="Quit")
quit_button.place(relwidth=1, relheight=1)
alarm_entry = tk.Entry(up_frame, font=40)
alarm_entry.insert(3, "esimerkiksi - 15:45")
alarm_entry.place(relx=0.7, rely=0, relwidth=0.3, relheight=0.45)
# label2 = tk.Label(lower_frame, bg='white')
root.overrideredirect(True)
root.geometry("{0}x{1}+0+0".format(root.winfo_screenwidth(), root.winfo_screenheight()))
root.focus_set()
def time():
string = strftime('%H:%M:%S')
label.config(text = string, font='40')
label.after(1000, time)
time()
它在第33行给了我这个错误。
AttributeError: 'function' object has no attribute 'strftime'