"Time series five" personalized clock and Stopwatch upgrade version

Source: Internet
Author: User

From yesterday to now, I've been working on this seemingly super-simple clock. The interface is very simple and generous.

It was simple, but the question of alignment was a complete mess. Who told the author not to explain clearly.

Reference: http://bbs.fishc.com/thread-77638-1-1.html

Next, we're going to fix this step.

--------------------------------------------------------------------------------------------------------------- -

Step 1

Attention. This is a line printing to print out this kind of graphics, this dictionary is stored in the list, why is the list stored? Because later.

A number, we are going to print in the next three parts.

The elements here should be aligned as much as possible, because the most troublesome thing about this program is the neat output. The stroke of the first/position 0 element is uniformly centered.

Take 0 for example, position 0 (a horizontal) in addition to 1 and 4, in other numbers are to surround, so the two sides of the space is actually left to the vertical!!!

1LCD = {20: [" _ ","| |","|_|"],31: ["   ","  |","  |"],42: [" _ "," _|","|_ "],53: [" _ "," _|"," _|"],64: ["   ","|_|","  |"],75: [" _ ","|_ "," _|"],86: [" _ ","|_ ","|_|"],97: [" _ ","  |","  |"],Ten8: [" _ ","|_|","|_|"], One9: [" _ ","|_|"," _|"] A } -  -  forNuminchLCD: the      forIinchLcd[num]: -         PrintI

If the output is this neat number (the code is output vertically), it means that we have painstakingly entered the list element is correct.

Step 2

next to the code, the full version is below.

1 #Coding:utf-82 3 Import Time4 5 #Divide the time, minutes, seconds, respectively, into the lower three parts and6 #stored separately in an empty list (empty)7 8 defNUM2LCD (time):9ET = ["","",""]TenShiwei = TIME/10 OneGewei = time% 10 A  -     forIinchRange (0, 3): -Et[i] = Lcd[shiwei][i] +Lcd[gewei][i] the      -    returnet -  - #Time.localtime () is a tuple that outputs the current date + #T.tm_hour is when the t.tm_min is minutes - #The most critical part of this function is to separate the previous + #the list elements of the seconds are assembled into a list, which is then printed uniformly.  A  at defclock (): -t =time.localtime () -h =NUM2LCD (T.tm_hour) -m =NUM2LCD (t.tm_min) -s =NUM2LCD (t.tm_sec) -  inoutput = [h[0] + m[0] + s[0], h[1] + m[1] + s[1], h[2] + m[2] + s[2]] -     returnOutput

Note that the time shown here can be aligned entirely depending on whether the LCD dictionary is aligned, and the number of spaces before and after each value must be controlled.

--------------------------------------------------------------------------------------------------------------- ------------

1 #Coding:utf-8 2016/12/82 3 ImportOS, time4 5 #here, based on the above, the elements of each list are appended6 #One more space to make the numbers appear more beautiful7 8LCD = {90: [" _  ","| | ","|_| "],Ten1: ["    ","  | ","  | "], One2: [" _  "," _| ","|_  "], A3: [" _  "," _| "," _| "], -4: ["    ","|_| ","  | "], -5: [" _  ","|_  "," _| "], the6: [" _  ","|_  ","|_| "], -7: [" _  ","  | ","  | "],  -8: [" _  ","|_| ","|_| "], -9: [" _  ","|_| "," _| "], + } -  + #Divide the time, minutes, seconds, respectively, into the lower three parts and A #stored separately in an empty list (empty) at  - defNUM2LCD (time): -ET = ["","",""] -Shiwei = TIME/10 -Gewei = time% 10 -  in     forIinchRange (0, 3): -Et[i] = Lcd[shiwei][i] +Lcd[gewei][i] to      +    returnet -  the #Time.localtime () is a tuple that outputs the current date * #T.tm_hour is when the t.tm_min is minutes $ #The most critical part of this function is to separate the previousPanax Notoginseng #the list elements of the seconds are assembled into a list, which is then printed uniformly.  -  the defclock (): +t =time.localtime () Ah =NUM2LCD (T.tm_hour) them =NUM2LCD (t.tm_min) +s =NUM2LCD (t.tm_sec) -  $output = [H[0] +" "+ m[0] +" "+ s[0], h[1] +"."+ m[1] +"."+ s[1], h[2] +"."+ m[2] +"."+ s[2]] $     returnOutput -  -  the  whileTrue: -      forIinchclock ():Wuyi         PrintI theTime.sleep (1)  -Os.system ("CLS")
Clock full version

Because the distance between the time and minute, the minute and the second is added with a colon, and each time h[0] and m[0], m[0] and second s[0] is certain,

Since the colon itself occupies 1 spaces, the latter becomes this way. Therefore, add a space between h[0] m[0],m[0] and s[0].

1 " " " " " . " " . " " . " " . " + s[2]"

The stopwatch is similar in the same vein. This is not the case, just attach the code.

"Time series five" personalized clock and Stopwatch upgrade version

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.