资源简介
python满分大作业打地鼠,用graphics库编写,内含文档。
代码片段和文件信息
# button.py
from graphics import *
class Button:
“““A button is a labeled rectangle in a window.
It is activated or deactivated with the activate()
and deactivate() methods. The clicked(p) method
returns true if the button is active and p is inside it.“““
def __init__(self win center width height label):
“““ Creates a rectangular button eg:
qb = Button(myWin Point(3025) 20 10 ‘Quit‘) “““
wh = width/2.0 height/2.0
xy = center.getX() center.getY()
self.xmax self.xmin = x+w x-w
self.ymax self.ymin = y+h y-h
p1 = Point(self.xmin self.ymin)
p2 = Point(self.xmax self.ymax)
self.rect = Rectangle(p1p2)
self.rect.setFill(‘lightgray‘)
self.rect.draw(win)
self.label = Text(center label)
self.label.draw(win)
self.deactivate()
def clicked(self p):
“RETURNS true if button active and p is inside“
return self.active and \
self.xmin <= p.getX() <= self.xmax and \
self.ymin <= p.getY() <= self.ymax
def getLabel(self):
“RETURNS the label string of this button.“
return self.label.getText()
def activate(self):
“Sets this button to ‘active‘.“
self.label.setFill(‘black‘)
self.rect.setWidth(2)
self.active = 1
def deactivate(self):
“Sets this button to ‘inactive‘.“
self.label.setFill(‘slategrey‘)
self.rect.setWidth(1)
self.active = 0
- 上一篇:Python物理建模初学者指南
- 下一篇:pytesser_v0.0.1.zip
相关资源
- Python物理建模初学者指南
- pyltp wheel python3.5 3.6
- Python自然语言处理(PDF高清书籍分享
- 基于Python自相关法时间序列的时间延
- 利用 Python 进行数据分析 中文第二版
- Problem Solving with Algorithms and DataStruct
- python计算机二级教程1-11章
- python自然语言处理中文版.pdf223593
- python的pywt库
- PTVS 2.2 VS 2013 补充工具 自动提示功能
- data-science-using-python-r
- Python for VS2012官方版
- A Byte of Python(简明Python教程)(第
- wxPython 2.8 Application Development Cookbook
- 终极自动化测试环境搭建:Selenium+E
- 基于django搭建的博客
- SHA-3 哈希摘要算法 python 源代码及官方
- sha3 python 史上最全最详细的正确实现
- Hands On Machine Learning with Python: Concept
- Python for everybody (EDX)
- Python数据分析与机器学习-贝叶斯实现
-
PyGob
ject(pygtk3)全解——超多代码 - matlab转python的教程
- Python37ForDelphi7.zip221420
- knn算法识别mnist图片-python3
- Python for Data Analysis(2nd )中文带书签
- python 截图 抓图 源码
- Python3实现多图拼接
- 量化交易之路用Python做股票量化分析
- 用Python写网络爬虫.pdf 高清带书签
评论
共有 条评论