def date_time_check(): if clock.tick() != label_clock['text']: label_clock['text'] = clock.tick() if clock.date() != label_date['text']: label_date['text'] = clock.date() label_clock.after(200, date_time_check) label_date.after(3600000, date_time_check)
def tick(): clock.tick() for event in pygame.event.get(): if event.type == pygame.QUIT: quit() elif event.type == pygame.VIDEORESIZE: resize(event.size) elif event.type == pygame.KEYDOWN: if event.key == ord("q"): quit() sprite.get_screen("game").fill((100, 130, 160)) level.render() screensprite = pygame.transform.scale(sprite.get_screen("game"), screen_size) display.blit(screensprite, (0, 0)) pygame.display.flip()
def 服务(): try: 运行时间 = 0 while True: time_passed = clock.tick() if time_passed < 0.01: # 限制性能 clock.back() time.sleep(0.01) time_passed = clock.tick() if time_passed > 0.02: time_passed = 0.02 # 保证刷新均匀 运行时间 += time_passed env.主世界.tp(time_passed) env.发送单位 = env.主世界.单位池 env.发送物品 = env.主世界.物品池 except Exception as e: env.主世界.保存() print('保存了。') raise e
sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.run(1) sensor.skip_frames(30) v = video.open("/sd/capture.avi", record=1, interval=200000, quality=50) i = 0 print('Initialization done.') print('MAiXPy imaging app running...') tim = time.ticks_ms() while True: tim = time.ticks_ms() clock.tick() img = sensor.snapshot() fps = clock.fps() img.draw_string(2,2,'MAiXPy Real Time Imaging', color=(0, 255,0)) img.draw_string(2,10,'Rate = {:2.1f} fps'.format(fps), color=(0,255,0)) lcd.display(img) if i < 100: img_len = v.record(img) print("record",i, time.ticks_ms() - tim) i += 1 if i == 100: print('Recording finished') v.record_finish() i = 200
def update(): new_window.attributes('-topmost', True) clockWindow.config(text=clock.tick()) root.after(200, update)
def completeSmartMirror(): ''' Tkinter UI that takes no input, but displays 4 panels that pull information from several APIs to create a smart mirror look-alike''' # Beginning of tkinter root = Tk() root.title('Smart Mirror') root.configure( background='black') # creating the object and making it black # Creating the dimessions of the screen screen_width = root.winfo_screenwidth() screen_height = root.winfo_screenheight() root.geometry('{}x{}'.format( screen_width, screen_height)) # makes object the size of the screen root.overrideredirect(True) root.overrideredirect(False) root.attributes('-fullscreen', True) # fonts for variables font_time = tkinter.font.Font(family='Helvetica', size=x_large_text_size) font_date = tkinter.font.Font(family='Helvetica', size=medium_text_size) font_conditions = tkinter.font.Font(family='Helvetica', size=medium_text_size) font_news = tkinter.font.Font(family='Helvetica', size=medium_text_size) font_calendar = tkinter.font.Font(family='Helvetica', size=medium_text_size) font_weather = tkinter.font.Font(family='Helvetica', size=large_text_size) #------------------------------------------------------------------------------------ # Frames for placing labels into frame_top = Frame(root, background='black') # frame for top half of screen frame_bottom = Frame(root, background='black') # frame for bottom half of screen # TOP LEFT FRAME FOR DATE AND CLOCK frame_t_left = Frame(frame_top, background='black') # top left frame label_date = Label(frame_t_left, font=font_date, bg='black', fg='white') label_clock = Label(frame_t_left, font=font_time, bg='black', fg='white') label_clock['text'] = clock.tick() label_date['text'] = clock.date() def date_time_check(): if clock.tick() != label_clock['text']: label_clock['text'] = clock.tick() if clock.date() != label_date['text']: label_date['text'] = clock.date() label_clock.after(200, date_time_check) label_date.after(3600000, date_time_check) # Layout of date and time label_clock.pack(side=TOP, anchor=W) label_date.pack(side=TOP, anchor=W) #-------------------------------------------------------------------------------------- # TOP RIGHT FRAME FOR WEATHER frame_t_right = Frame(frame_top, background='black') label_weather = Label(frame_t_right, font=font_weather, bg='black', fg='white') label_weather_conditions = Label(frame_t_right, font=font_conditions, bg='black', fg='white') label_weather['text'] = weather.get_weather('Minneapolis') label_weather_conditions['text'] = weather.get_weather_conditions( 'Minneapolis') label_weather.pack(side=TOP, anchor=E) label_weather_conditions.pack(side=TOP, anchor=W) # Code commented out below is for adding icons from weather api, but they don't look good #img = ImageTk.PhotoImage(Image.open(BytesIO(weather.get_icon()))) #label_weather_icon = Label(image=img) #label_weather_icon.pack(side=TOP, anchor=W) def weather_update(): if weather.get_weather('Minneapolis') != label_weather['text']: label_weather['text'] = weather.get_weather('Minneapolis') label_weather.after(3600000, weather_update) # -------------------------------------------------------------------------------------- # BOTTOM RIGHT FRAME FOR NEWS HEADLINES frame_b_left = Frame(frame_bottom, background='black') frame_b_right = Frame(frame_bottom, background='black') label_news = Label(frame_b_left, font=font_news, bg='black', fg='white', wraplength=800) # Creates function that iterates through list of headlines label_news.pack(side=BOTTOM, anchor=SW) def change_headlines(): global headlines headlines = news.get_news_headlines() label_news.after(21600000, change_headlines) # change_headlines() global n n = 0 def get_headline(): global headlines global n label_news['text'] = headlines[n] n += 1 if n > len(headlines) - 1: n = 0 label_news.after(15000, get_headline) #------------------------------------------------------------------------------------- # BOTTOM LEFT FRAME FOR CALENDAR label_calendar = Label(frame_b_left, font=font_calendar, bg='black', fg='white', wraplength=800) label_calendar.pack(side=TOP, anchor=W) def calendar_text(): label_calendar['text'] = str( mirror_calendar.dict_to_str(mirror_calendar.get_events())) label_calendar.after(21600000, calendar_text) #-------------------------------------------------------------------------------------- # Call functions that were created date_time_check() weather_update() # get_headline() # calendar_text() #------------------------------------------------------------------------------------- # Packing to display the objects that have been created frame_t_left.pack(side=LEFT, anchor=N, padx=40, pady=40) frame_t_right.pack(side=RIGHT, anchor=NE, padx=40, pady=40) frame_top.pack(expand=TRUE, fill=BOTH, side=TOP) frame_b_left.pack(side=LEFT, anchor=SW, padx=40, pady=40) frame_b_right.pack(side=LEFT, anchor=SW, padx=40, pady=40) frame_bottom.pack(expand=TRUE, fill=BOTH, side=BOTTOM) root.mainloop()
clock = clock.clock() env.主世界 = world.世界() 世界 = env.主世界 print('主循环启动了。') import net_server import atexit print('按ctrl-c来安全退出。') atexit.register(env.主世界.保存) try: 运行时间 = 0 while True: time_passed = clock.tick() if time_passed < 0.01: #限制性能 clock.back() time.sleep(0.01) time_passed = clock.tick() if time_passed > 0.02: time_passed = 0.02 #保证刷新均匀 运行时间 += time_passed env.主世界.tp(time_passed) env.发送单位 = env.主世界.单位池 env.发送物品 = env.主世界.物品池 except Exception as e: env.主世界.保存() print('保存了。') raise e
def game_loop(): x = display_width * 0.45 y = display_height * 0.60 x_change = 0 y_change = 0 crashed = False thing_startx = random.randrange(0, display_width) thing_starty = -600 thing_speed = 1 thing_width = 100 thing_height = 100 dodged = 0 while not crashed: for event in pygame.event.get(): if event.type == pygame.QUIT: crashed = True if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: x_change = -1 elif event.key == pygame.K_RIGHT: x_change = 1 elif event.key == pygame.K_UP: y_change = -1 elif event.key == pygame.K_DOWN: y_change = 1 if event.type == pygame.KEYUP: if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT or event.key == pygame.K_UP or event.key == pygame.K_DOWN: x_change = 0 y_change = 0 x += x_change y += y_change gameDisplay.fill(white) things(thing_startx, thing_starty, thing_width, thing_height, black) thing_starty += thing_speed car(x, y) things_dodged(dodged) if x > (display_width - car_width) or x < 0: crashed = True if thing_starty > display_height: thing_starty = 0 - thing_height thing_startx = random.randrange(0, display_width) dodged += 1 thing_speed += 1 thing_width += (dodged * 1.2) if thing_starty > display_height: thing_starty = 0 - thing_height thing_startx = random.randrange(0, display_width) if y < thing_starty + thing_height: print('y crossover') if x > thing_startx and x < thing_startx + thing_width or x + car_width > thing_startx and x + car_width < thing_startx + thing_width: print('x crossover') crash() #print(event) # gameDisplay.fill(white) # things(thing_startx, thing_starty, thing_width, thing_height, black) # thing_starty += thing_speed car(x, y) pygame.display.update() clock.tick(60)
player_group = pygame.sprite.Group() player_group.add(player) subs_group = pygame.sprite.Group() for a in range(5): for y in range(10): x = random.randint(50, width_screen-50) sub = Submarine("submarine.png", [x,y*30+40], 3) subs_group.add(sub) balls_group = pygame.sprite.Group() shoot_group = pygame.sprite.Group() while lifes > 0: clock.tick(FPS) for event in pygame.event.get(): if event.type == pygame.QUIT : lifes = 0 if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: lifes = 0 for sub in subs_group: if sub.rect.right >= width_screen or sub.rect.left <= 0: sub.flip() sub.move() shoot = sub.shoot() if shoot != None: shoot_group.add(shoot)