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() 

빠른 도움이 필요!

답변

0

나는 ...

나의 추천 당신이 Tkinter의 부분을 던져 거북이 완전히이 작업을 수행 할 것입니다 tkinder 내 거북이 그래픽을 결합 할 수없는 것.

# import winsound 
from turtle import Turtle, Screen, Terminator 
from datetime import datetime 

screen = Screen() 
screen.mode('logo') 
screen.setup(700, 700) 
screen.title('Alarm Clock') 

wochentag_list = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] 
monat = ['Jan.', 'Feb.', 'Mar.', 'Apr.', 'May', 'June', 'July', 'Aug.', 'Sep.', 'Oct.', 'Nov.', 'Dec.'] 

FONT_SIZE = 14 
FONT = ('Courier', FONT_SIZE, 'bold') 
BUTTON_SIZE = 40 
CURSOR_SIZE = 20 

def jump(turtle, distanz): 
    turtle.penup() 
    turtle.forward(distanz) 
    turtle.pendown() 

def hand(turtle, laenge, spitze): 
    turtle.fd(laenge * 1.10) 
    turtle.rt(90) 
    turtle.fd(spitze/20.0) 
    turtle.lt(120) 
    turtle.fd(spitze) 
    turtle.lt(120) 
    turtle.fd(spitze) 
    turtle.lt(120) 
    turtle.fd(spitze/20.0) 

def make_hand_shape(turtle, name, laenge, spitze): 
    turtle.reset() 
    jump(turtle, -laenge * 0.15) 
    turtle.begin_poly() 
    hand(turtle, laenge, spitze) 
    turtle.end_poly() 
    screen.register_shape(name, turtle.get_poly()) 

def clockface(radius): 
    face = Turtle() 
    face.pensize(3) 
    face.speed('fastest') 

    jump(face, radius) 
    face.left(90) 
    face.circle(radius) 
    face.right(90) 
    jump(face, -radius) 
    face.pensize(7) 

    radius *= 0.8 

    jump(face, radius) 

    for i in range(60): 
     if i % 5 == 0: 
      face.forward(25) 
      jump(face, -25) 
     else: 
      face.dot(4) 

     face.left(90) 
     face.penup() 
     face.circle(radius, 6) 
     face.pendown() 
     face.right(90) 

    face.hideturtle() 

def setup(): 
    hand = Turtle() 

    # clock hands 
    make_hand_shape(hand, 'second_hand', 125, 5) 
    make_hand_shape(hand, 'minute_hand', 130, 5) 
    make_hand_shape(hand, 'hour_hand', 90, 5) 

    hand.reset() 
    hand.hideturtle() 

    clockface(200) 

    second_hand = Turtle() 
    second_hand.shape('second_hand') 
    second_hand.color('grey') 

    minute_hand = Turtle() 
    minute_hand.shape('minute_hand') 
    minute_hand.color('#505050') 

    hour_hand = Turtle() 
    hour_hand.shape('hour_hand') 
    hour_hand.color('#191919') 

    for hand in second_hand, minute_hand, hour_hand: 
     hand.shapesize(outline=3) 
     hand.speed('fastest') 

    return second_hand, minute_hand, hour_hand 

def wochentag(t): 
    return wochentag_list[t.weekday()] 
# date 
def datum(z): 
    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 

    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') 

    try: 
     marker1.undo() 
     marker1.write(wochentag(t), align='center', font=FONT) 

     marker2.undo() 
     marker2.write(datum(t), align='center', font=FONT) 

     marker3.undo() 
     marker3.write(current_time, align='center', font=FONT) 

     second_hand.setheading(6 * sekunde) 
     minute_hand.setheading(6 * minute) 
     hour_hand.setheading(30 * stunde) 

     screen.update() 

     if current_time in alarm_clock_dic: 
      #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) 
      pass 

     screen.ontimer(tick, 100) 
    except Terminator: 
     screen.bye() 

def set_alarm(x, y): 
    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')) 

    pointSize = screen.textinput(current_time, "Enter Time") 
    alarm_clock_dic.append(pointSize) 

marker1 = Turtle(visible=False) 
marker1.penup() 
marker1.forward(65) 
marker1.color('grey') 
marker1.write('', align='center', font=FONT) 

marker2 = Turtle(visible=False) 
marker2.penup() 
marker2.backward(85) 
marker2.color('grey') 
marker2.write('', align='center', font=FONT) 

marker3 = Turtle(visible=False) 
marker3.penup() 
marker3.goto(0, 220) 
marker3.color('grey') 
marker3.write('', align='center', font=FONT) 

screen.tracer(False) 
second_hand, minute_hand, hour_hand = setup() 

button = Turtle('circle') 
button.shapesize(BUTTON_SIZE/CURSOR_SIZE, outline=2) 
button.color('black', 'red') 
button.penup() 
button.goto(250, 250) # move the button into position 

marker4 = Turtle(visible=False) 
marker4.penup() 
marker4.goto(button.xcor(), button.ycor() - BUTTON_SIZE/2 - FONT_SIZE - 2) 
marker4.write('Set Alarm', align='center', font=FONT) 

screen.update() 

alarm_clock_dic = [] 

button.onclick(set_alarm) 

tick() 

screen.mainloop() 
: 당신은 내가 단추와 거북이와 파이썬 3에 도입 된 textinput(title, prompt) 기능을 사용하여 아래 다시 실행 한 알람 설정에 대한 Tkinter를 필요하는 것 (I은 또한 당신의 코드를 약간 수정 된 것)

귀찮은 날짜 시간에 응답하도록 알람을 울리지 못하는 것 같습니다.

내 코드 디자인에서 어떻게 작동하는지 힌트를 표시했지만 테스트하지는 않았습니다. 나는 왜 winsound 관련 코드를 주석으로 처리했는지 winsound 라이브러리를 가지고 있지 않다 - 내가 아는 것은 아무 문제가 없다.

enter image description here