In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to achieve typing training procedures in Python. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
1. The characters on the keyboard need to be generated, and the string module generates characters.
Of course you can do it from 0 to 9. Amura Zjimi a koz! Wait, hold up the keys on the keyboard one by one.
Import string# enumerates numbers string.digits > 0123456789 enumerates lowercase letters string.ascii_lowercase > 'abcdefghijklmnopqrstuvwxyz'# enumerates uppercase letters string.ascii_uppercase >' ABCDEFGHIJKLMNOPQRSTUVWXYZ'# enumerates all punctuation marks string.punctuation >! "# $% &\'() * +, -. /: ? @ [\\] ^ _ `{|} ~'# enumerate all the blank characters string.whitespace >'\ t\ n\ r\ x0b\ x0c' string.ascii_letters = string.ascii_lowercase + string.ascii_uppercasestring.printable = string.ascii_letters + string.digits + string.whitespace + string.punctuation
2. Judge the relevant reading and writing of the rest.
From tkinter import * import randomimport stringfrom datetime import datetime root = Tk () root.title ("Python typing exercise By: breeze Python") Label (root, text=' system topic:') .grid (row=0) Label (root, text=' user answer:') .grid (row=1) Label (root, text=' test results:') .grid (row=2) v1 = StringVar () v2 = StringVar () v3 = StringVar () v1.set ("Click the 'start Test' button to start the question") e1 = Entry (root, text=v1) State='disabled', width=40, font= ('Song', 14)) e2 = Entry (root, textvariable=v2, width=40, font= ('Song', 14)) E3 = Label (root, textvariable=v3, width=40, font= ('Song', 10), foreground='red') e1.grid (row=0, column=1, padx=10, pady=20) e2.grid (row=1, column=1, padx=10, pady=20) e3.grid (row=2, column=1, padx=10, pady=20) text = Text (root, width=80, height=7) text.grid (row=4, column=0, column=0 Pady=5) class TypingTest: def _ init__ (self): self.time_list = [] self.letterNum = 20 self.letterStr = '.join (random.sample (string.printable.split (') [0]) Self.letterNum)) self.examination_paper =''def time_calc (self): self.time_list.append (datetime.now ()) yield def create_exam (self): text.delete (0.0, END) # e3.delete (0, END) v1.set (self.letterStr) self.time_calc (). _ next__ () text.insert (END) "start:% s\ n"% str (self.time_list [- 1]) user_only1.config (state='active') def score (self): wrong_index = [] self.time_calc (). _ _ next__ () text.insert (END) "end:% s\ n"% str (self.time_list [- 1]) use_time = (self.time_list [- 1]-self.time_list [- 2]). Seconds self.examination_paper = v2.get () if len (self.examination_paper) > self.letterNum: v3.set ("input data is incorrect Else: right_num = 0 for z in range (len (self.examination_paper)): if self.examination_ paper [z] = = self.letterStr [z]: right_num + = 1 else: wrong_index.append (z) If right_num = = self.letterNum: v3.set ("exactly Correct rate% .2f% usage:% s seconds "% ((right_num * 1.0) / self.letterNum * 100,use_time)) else: v3.set (" accuracy% .2f% usage:% s seconds "% ((right_num * 1.0) / self.letterNum * 100, use_time)) # e2.delete (0 END) text.insert (END, "title:% s\ n"% self.letterStr) tag_info = list (map (lambda x: '4.' + str (x + 3), wrong_index) text.insert (END) "answer:% s\ n"% self.examination_paper) for i in range (len (tag_info)): text.tag_add ("tag1", tag_ info [I]) text.tag_config ("tag1", background='red') user_only1.config (state='disabled') TypingTest = TypingTest () Button (root, text= "start testing", width=10 Command=TypingTest.create_exam) .grid (row=3, column=0, sticky=W, padx=30, pady=5) user_only1 = Button (root, text= "submission", width=10, command=TypingTest.score, state='disable') user_only1.grid (row=3, column=1, sticky=E, padx=30, pady=5) mainloop ()
3, the final code will be packaged into an exe tool, you can break away from the python environment, execute exe files on a separate computer, and you can practice typing.
This is the end of this article on "how to achieve typing training in Python". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.