Home > other >  Turtle countdown interface response, not stuck, beg bosses help me have a look
Turtle countdown interface response, not stuck, beg bosses help me have a look

Time:09-19

Beginners python wrote a cycle countdown script, have suspended (press the keyboard space), the reset function (press the keyboard enter), two threads, a thread cycle countdown and turtle map digital tube, a thread is responsible for monitoring the keyboard keys, Shared class action attribute to achieve timing reset function, but the script to the countdown, but a pause (such as suspended after a period of time) or timing end (end of the time I want to make the picture remain stationary state, and to monitor whether there is a return to reset the countdown) interface will not response, trouble bosses to help me see,
Ring a bell and specify the time period function, reading the same directory mp3 files, and by adding a thread to ring the bell, guarantee the countdown is not affected by the bell, by adding a dictionary


 

The import turtle
The import time
The import threading
The import pygame, OS, re, sys
The from mutagen. Mp3 import mp3
The from pynput. The rid_device_info_keyboard import Key, the Listener


The class mainApp () :
Def __init__ (self, total_time bell_set) :
Self. Total_time=total_time
Self. Bell_set=bell_set
Self. Action_space=True
The self. The action_enter=False
Self. Action_esc=True
Self. Script_path=OS. Path. Abspath (OS) path) dirname (__file__) # OS. The path. The dirname (OS) path) realpath (sys. The executable)) # #
Print (self. Script_path)
For file_name in OS. Listdir (self. Script_path) :
If re. Match (". * (. Mp3) $", file_name) :
Self. MusicPath=self. Script_path + "\ " + file_name
Self. Audio=MP3 (self. MusicPath)
Pygame. Mixer. The init () # initialize all introduced module
The self. The lock=threading. The lock ()


Def reaching (self, num) :
For I in range (num) :
Pygame. Mixer. Music. The load (self. MusicPath) # loaded music, music can be a ogg, mp3 format, such as
Pygame. Mixer. Music. Play () # play loaded music
Time. Sleep (int (self. Audio. Info. Length)/2) # for the length of each song, make the program length is equal to the songs of survival time

Def rang_thread (self, old_minuts old_second, ring_time) :
Num=ring_time [old_minuts + + old_second] ':'
Threading. Thread (target=self. Reaching the args=(num,)). The start ()

Def drawLine (self, the draw) :
Turtle. Penup ()
Turtle. Pendown () if the draw the else turtle. Penup ()
Turtle. Fd (130)
Turtle. Right (90)

Def drawDigit (self, digit) :
Self. DrawLine (True) if digit,3,4,5,6,8,9 [2] the else in the self. The drawLine (False)
Self. DrawLine (True) if digit,1,3,4,5,6,7,8,9 [0] the else in the self. The drawLine (False)
Self. DrawLine (True) if digit,2,3,5,6,8,9 [0] the else in the self. The drawLine (False)
Self. DrawLine (True) if digit,2,6,8 [0] the else in the self. The drawLine (False)
Turtle. Left (90)
Self. DrawLine (True) if digit,4,5,6,8,9 [0] the else in the self. The drawLine (False)
Self. DrawLine (True) if digit,2,3,5,6,7,8,9 [0] the else in the self. The drawLine (False)
Self. DrawLine (True) if digit,1,2,3,4,7,8,9 [0] the else in the self. The drawLine (False)
Turtle. Left (180)
Turtle. Penup ()
Turtle. Fd (50)

Def drawTime (self, localtime) :
Turtle. Pencolor (" green ")
For I in localtime:
If I==': :
Turtle. Goto (0, 80)
Turtle. Pendown ()
Turtle. Circle (3)
Turtle. Penup ()
Turtle. Goto (0-80)
Turtle. Pendown ()
Turtle. Circle (3)
Turtle. Penup ()
Turtle. Goto (0, 0)
# turtle. Write (' : ', the font=(18, "Arial", "normal"))
Turtle. Fd (50)
The else:
Self. DrawDigit (eval (I))

Def drawTime2 (self, localtime) :
For I in localtime:
Self. DrawDigit (eval (I))

Def reset (self, x, y) :
Turtle. Goto (x, y)
Turtle. Pencolor (" black ")
Self. DrawTime2 (" 88 ")
Turtle. Goto (x, y)

Def timing_process (self) :
Turtle. Setup (810410)
Turtle. Screensize (800400, "black")
Turtle. Penup ()
Turtle. Speed (0)
Turtle. The turtle (). Screen. Delay (0)
Turtle. Fd (360)
Turtle. Pensize (10)
Self. DrawTime (self. Total_time)
Turtle. Hideturtle ()
Old_minuts=self. Total_time. Split (' : ') [0]
Old_second=self. Total_time. Split (' : ') [1]
Ring_time=self. Bell_set
Sys_old_second=time. Strftime (' % S ', and time. The localtime ())
While the self. Action_esc:
If self. Action_enter:
Turtle. Tracer (0)
Self. Reset (50, 0)
The self. The reset (360, 0)
Self. DrawTime (self. Total_time)
Old_minuts=self. Total_time. Split (' : ') [0]
Old_second=self. Total_time. Split (' : ') [1]
Turtle. The update ()
The self. The action_enter=False
Self. Action_space=False
The continue
If self. Action_space:
# sys_old_second=time. Strftime (' % S 'time. The localtime ())
Pass
The else:
Sys_old_second=time. Strftime (' % S ', and time. The localtime ())
The continue

If the int (old_second)==0 and int (old_minuts)!=0:
# according to the system time delay
Sys_now_second=time. Strftime (' % S ', and time. The localtime ())
If sys_now_second==sys_old_second:
The continue
The else:
Sys_old_second=sys_now_second
The execute=True

Turtle. Tracer (0)
Now_minuts=(STR (int (old_minuts) - 1) if len (STR (int (old_minuts) - 1))==2 else '0' + STR (int (old_minuts) - 1))
The self. The reset (360, 0)
Turtle. Pencolor (" green ")
Self. DrawTime2 (now_minuts)
Self. Reset (50, 0)
Turtle. Pencolor (" green ")
Self. DrawTime2 (" 59 ")
Old_second="59"
Old_minuts=now_minuts
Turtle. The update ()
The continue
Elif int (old_second)==0 and int (old_minuts)==0:
The continue

# according to the system time delay
Sys_now_second=time. Strftime (' % S ', and time. The localtime ())
If sys_now_second==sys_old_second:
The continue
The else:
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related