资源简介
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
相关资源
- Instant Pygame for Python Game Development How
- Biopython Tutorial
- Think Python 2nd
- 一个小小的表白程序(python)
- Python课堂笔记(高淇400集第一季)
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
评论
共有 条评论