0
나는이 자명종을 만들었지 만 적어도 내 모든 거북이 그래픽을 tkinder와 결합 할 수는없는 것 같습니다. 또한 귀결 된 날짜 시간에 응답하도록 내 경보가 표시되지 않는 것 같습니다.tkinter와 거북이, 알람 시계 python을 결합하십시오.
알람 시계
import winsound
import turtle
from turtle import *
from datetime import datetime
import tkinter
from tkinter import *
#combine turtle and tkinder
root = tkinter.Tk()
root.title("Alarm Clock")
cv = tkinter.Canvas(root, width=700, height=700)
cv.pack(side = tkinter.LEFT)
sc = turtle.RawTurtle(cv)
sc.setpos(0, -200)
s = sc.getscreen()
s.delay(0)
#turtle draws a circle
for aColor in ["black", "black", "black", "black"]:
sc.color(aColor)
sc.pensize(3)
def drawPoly(t, num_sides, side_length):
for i in range(num_sides):
t.forward(side_length)
t.left(90/num_sides)
drawPoly(sc, 320, 1)
sc.color("white")
sc.fd(100)
def jump(distanz, winkel=0):
penup()
right(winkel)
forward(distanz)
left(winkel)
pendown()
def hand(laenge, spitze):
fd(laenge*1.10)
rt(90)
fd(spitze/20.0)
lt(120)
fd(spitze)
lt(120)
fd(spitze)
lt(120)
fd(spitze/20.0)
def make_hand_shape(name, laenge, spitze):
reset()
jump(-laenge*0.15)
begin_poly()
hand(laenge, spitze)
end_poly()
hand_form = get_poly()
register_shape(name, hand_form)
def clockface(radius):
reset()
pencolor("black")
pensize(7)
for i in range(60):
jump(radius)
if i % 5 == 0:
fd(25)
jump(-radius-25)
else:
dot(4)
jump(-radius)
rt(6)
def setup():
global second_hand, minute_hand, hour_hand, sc
mode("logo")
#clock hands
make_hand_shape("second_hand", 125, 5)
make_hand_shape("minute_hand", 130, 5)
make_hand_shape("hour_hand", 90, 5)
clockface(160)
second_hand = Turtle()
second_hand.shape("second_hand")
second_hand.color("grey", "grey")
minute_hand = Turtle()
minute_hand.shape("minute_hand")
minute_hand.color("#505050", "#505050")
hour_hand = Turtle()
hour_hand.shape("hour_hand")
hour_hand.color("#191919", "#191919")
for hand in second_hand, minute_hand, hour_hand:
hand.resizemode("user")
hand.shapesize(1, 1, 3)
hand.speed(0)
ht()
sc.ht()
sc.pu()
sc.bk(85)
def wochentag(t):
wochentag = ["Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday", "Sunday"]
return wochentag[t.weekday()]
#date
def datum(z):
monat = ["Jan.", "Feb.", "Mar.", "Apr.", "May", "June",
"July", "Aug.", "Sep.", "Oct.", "Nov.", "Dec."]
j = z.year
m = monat[z.month - 1]
t = z.day
return "%s %d %d" % (m, t, j)
def tick():
t = datetime.today()
sekunde = t.second + t.microsecond*0.000001
minute = t.minute + sekunde/60.0
stunde = t.hour + minute/60.0
try:
tracer(False) # Terminator can occur here
sc.setpos(0, 100)
sc.clear()
sc.home()
sc.forward(65)
sc.pencolor("grey")
sc.write(wochentag(t),
align="center", font=("Courier", 14, "bold"))
sc.back(150)
sc.write(datum(t),
align="center", font=("Courier", 14, "bold"))
sc.goto(-20, 200)
d = datetime.now().strftime("%Y-%m-%d %H:%M")
current_time = datetime.strptime(d, "%Y-%m-%d %H:%M").strftime("%Y-%m-%d %I:%M %p")
sc.write(current_time,
align="center", font=("Courier", 14, "bold"))
tracer(True)
second_hand.setheading(6*sekunde) # or here
minute_hand.setheading(6*minute)
hour_hand.setheading(30*stunde)
tracer(True)
ontimer(tick, 100)
except Terminator:
pass
def main():
tracer(False)
setup()
tracer(True)
tick()
return "EVENTLOOP"
if __name__ == "__main__":
mode("logo")
main()
d = datetime.now().strftime("%Y-%m-%d %H:%M")
current_time = (datetime.strptime(d, "%Y-%m-%d %H:%M").strftime("%Y-%m-%d %I:%M %p"))
print (datetime.strptime(d, "%Y-%m-%d %H:%M").strftime("%Y-%m-%d %I:%M %p"))
#combine turtle and tkinder
frame = tkinter.Frame(root)
frame.pack(side = tkinter.LEFT,fill=tkinter.BOTH)
pointLabel = tkinter.Label(frame,text="Set Alarm")
pointLabel.pack()
#button sets imputed time and date for alarm to start
pointSize = tkinter.StringVar()
pointEntry = tkinter.Entry(frame,textvariable=pointSize)
pointEntry.pack()
pointSize.set(current_time)
alarm_clock_dic = []
def quitHandler():
alarm_clock_dic.append(pointSize)
cmd_Button = tkinter.Button(frame, text = "Enter Time", command=quitHandler,
bg ='grey', fg = 'white')
cmd_Button.pack()
if alarm_clock_dic == (current_time):
winsound.PlaySound("SystemExit", winsound.SND_LOOP)
winsound.PlaySound("SystemExit", winsound.SND_LOOP)
winsound.PlaySound("SystemExit", winsound.SND_LOOP)
winsound.PlaySound("SystemExit", winsound.SND_LOOP)
winsound.PlaySound("SystemExit", winsound.SND_LOOP)
mainloop()
빠른 도움이 필요!