Coursera_An Introduction to Interactive Programming in Python_Mini-project # 3 Stopwatch
来源:互联网 发布:义乌司法拍卖淘宝网站 编辑:程序博客网 时间:2024/06/09 23:45
# "Stopwatch: The Game"import simplegui# define global variablescurrent_time = 0 #for example: 12 represents 1.2 seconds.total_win = 0total_try = 0flag = True# define helper function format that converts time# in tenths of seconds into formatted string A:BC.Ddef format(t): #format_D tenths of seconds #format_BC seconds #format_A minutes format_D = str(t % 10) # tenths of seconds format_string = str(t) temp1 = format_string[:(len(format_string)-1)] if len(temp1) == 0: format_BC = "00" format_A = "0" else: format_BC = int(temp1) % 60 format_A = str(int(temp1) / 60) if len(str(format_BC)) == 1: format_BC = "0" + str(format_BC) else: format_BC = str(format_BC) return format_A + ":" + format_BC + "." + format_D # define event handlers for buttons; "Start", "Stop", "Reset"def Start_button_handler(): timer.start() flag = False def Stop_button_handler(): timer.stop() flag = True if flag: global total_try total_try += 1 if current_time % 10 == 0: global total_win total_win +=1 def Reset_button_handler(): timer.stop() global current_time current_time = 0 global total_try total_try = 0 global total_win total_win = 0 # define event handler for timer with 0.1 sec intervaldef timer_handler(): global current_time current_time += 1# define draw handlerdef draw_handler(canvas): canvas.draw_text(format(current_time), (60, 80), 24, 'White') canvas.draw_text(str(total_win) + '/' + str(total_try), (110, 20), 20, 'Red')# create frameframe = simplegui.create_frame('Timer', 150, 150)frame.set_draw_handler(draw_handler)Start_button = frame.add_button('Start', Start_button_handler,50)Stop_button = frame.add_button('Stop', Stop_button_handler, 50)Reset_button = frame.add_button('Reset', Reset_button_handler, 50)timer = simplegui.create_timer(100, timer_handler)# register event handlers # start frameframe.start()# Please remember to review the grading rubric
0 0
- Coursera_An Introduction to Interactive Programming in Python_Mini-project # 3 Stopwatch
- Coursera_An Introduction to Interactive Programming in Python_Mini-project # 4 Pong
- Coursera_An Introduction to Interactive Programming in Python_Mini-project # 5 Memory
- Coursera_An Introduction to Interactive Programming in Python_Mini-project # 6 Blackjack
- Coursera_An Introduction to Interactive Programming in Python_Mini-project # 7 Spaceship
- Coursera_An Introduction to Interactive Programming in Python_Mini-project # 8 RiceRock
- Coursera_An Introduction to Interactive Programming in Python_Mini-project # 2 Guess the number
- Coursera_An Introduction to Interactive Programming in Python_Mini-project # 1 Rock-paper-scissors
- Coursera_An Introduction to Interactive Programming in Python_Music Player
- An Introduction to Interactive Programming in Python
- Mini-project # 4 - "Pong"___An Introduction to Interactive Programming in Python"RICE"
- Mini-project # 1 - Rock-paper-scissors-___An Introduction to Interactive Programming in Python"RICE"
- An Introduction to Interactive Programming in Python - Week zero
- An Introduction to Interactive Programming in Python - Week one
- An Introduction to Interactive Programming in Python - Week two
- An Introduction to Interactive Programming in Python - Week three
- An Introduction to Interactive Programming in Python(week 6)
- An Introduction to Interactive Programming in Python(week 7)
- M3U8格式讲解及实际应用分析
- [转]asp.net 前台绑定后台变量方法总结:<%= %> 和<%# %>的区别
- LA6575 Odd and Even Zeroes (2013-2014 ACM-ICPC Southwestern Europe Regional Contest F题) 规律
- C语言——字符和字符串常用处理函数
- A1和R1C1样式
- Coursera_An Introduction to Interactive Programming in Python_Mini-project # 3 Stopwatch
- ios中如何解析xml文件
- spring 面向切面编程AOP的原理
- iOS8中的playground新功能
- IT忍者神龟之Tomcat6 中文乱码
- hdu1828 Picture 扫描线
- 谷歌域名 http://91.213.30.151/
- fread与read的区别(文件io补充)
- javascript常用方法函数收集