最近看到好多同学在专升本,死记硬背的记单词,手抄的单词一页接着一页,不管是公众号,还是刷抖音,导出都能看到关于学英语、背单词的广告,教你快速提升。
不知道现在同学们背单词买的什么辅导学习的材料。
# -*- coding:utf-8 -*- import pygame import pygame.locals import random from win32con import WM_INPUTLANGCHANGEREQUEST import win32gui import win32api import copy class window_bg: def __init__(self, x, y): pygame.init() self.x = x self.y = y self.window = pygame.display.set_mode((x, y)) self.clock = pygame.time.Clock() self.fontobject = self.read_fontobject() # 字体类 self.num = 0 self.data_list_cache = [{"location": [int(x / 4), 0], "Font": "你好","data":"hello"}, {"location": [int(x / 4), 0], "Font": "(尤指苦战后获得的)胜利,成功,成就", "data": "triumph"}, {"location": [int(x / 4), 0], "Font": "发誓;做保证", "data": "pledge"}, {"location": [int(x / 4), 0], "Font": "摆姿势;造成、导致", "data": "pose"}, {"location": [int(x / 4), 0], "Font": "例行公事;常规;惯例", "data": "routine"}, {"location": [int(x / 4), 0], "Font": "赢得", "data": "attain"}, {"location": [int(x / 4), 0], "Font": "基础", "data": "foundation"}, {"location": [int(x / 4), 0], "Font": "资源;自然资源", "data": "resource"}, ] self.data_list = [] self.english_list = [] # 翻译存放处 self.NUM_code = list(range(48, 57 + 1)) # 数字按键所对应的码 self.ABC_code = list(range(97, 122 + 1)) # 字母按键所对应的码 self.NUM_ABC_code = self.NUM_code + self.ABC_code # 数字与字母按键所对应的码 # 切换成英文输入法 def Ctrl_English(self): # pygame只支持英文输入 hwnd = win32gui.GetForegroundWindow() win32api.SendMessage(hwnd, WM_INPUTLANGCHANGEREQUEST, 0, 0x0409) def read_fontobject(self): pygame.font.init() # 字体初始化 return pygame.font.Font('msyhbd.ttc', 15) # 显示输入框 def show_ziti(self, import_label, string_list, x, y, wide, height): # 输入标签,输入信息列表,位置x,位置y,宽度,高度 message = import_label + ''.join(string_list) pygame.draw.rect(self.window, (0, 100, 100), (x, y, wide, height), 0) # 0是全覆盖 pygame.draw.rect(self.window, (255, 255, 255), (x - 2, y - 2, wide + 4, height + 4), 1) # 1是边框 if len(message) != 0: self.window.blit(self.fontobject.render(message, 1, (255, 255, 255)), (x, y)) def pygame_event_get(self): for event in pygame.event.get(): # 事务处理(按键鼠标) if event.type == pygame.QUIT: exit() if event.type == pygame.locals.KEYDOWN: # 有键盘按下 # print('===',event.unicode) #按键所对应的值 # print(event.key) # 按键所对应的码 if event.unicode == '': # 输入法不是英文的,改成英文 if event.key in self.NUM_ABC_code: # 字母与数字按键所对应的码 self.Ctrl_English() event.unicode = chr(event.key) if event.key == pygame.locals.K_BACKSPACE: # 删除键 self.english_list = self.english_list[0:-1] elif event.key in self.ABC_code: # 账号密码支持小写字母与数字 self.english_list.append(event.unicode) elif event.key == pygame.locals.K_RETURN: # 回车键 for i_index, i in enumerate(self.data_list): if i["data"] == ''.join(self.english_list): self.data_list.pop(i_index) self.english_list=[] return # 位置下移,到一定的位置就消失 for i_index, i in enumerate(self.data_list): i["location"][1] += 0.5 if i["location"][1] > self.y - 200: self.data_list.pop(i_index) self.num += 1 if self.num % 150 == 0: # 深度复制 data = copy.deepcopy(random.choice(self.data_list_cache)) self.data_list.append(data) def pygame_display_update(self): self.window.fill((0, 0, 0)) # 背景色 self.show_ziti('翻译:', self.english_list, 300, 650, 200, 20) for i in self.data_list: self.show_ziti(i["Font"], [], i["location"][0], i["location"][1], 300, 20) pygame.display.update() self.clock.tick(26) # 窗口1秒刷新多少次 a = window_bg(800, 700) while True: a.pygame_event_get() a.pygame_display_update()
先来看看实现效果吧…程序输入你想测试的单词,然后系统出来你所输入的单词,答对就会消失,一直反复循环,不信你还记不住喽...