资源简介
这是一个用Python制作的汉诺塔演示小脚本,适合想入门Python的朋友!
代码片段和文件信息
from tkinter import Tk Canvas
def hanoi(n a b c report):
if n <= 0:
return
hanoi(n-1 a c b report)
report(n a c)
hanoi(n-1 b a c report)
class Tkhanoi:
def __init__(self n speed):
self.n = n
self.speed = speed
self.tk = tk = Tk(className=‘Hanoi‘)
self.canvas = c = Canvas(tkwidth=500height=500)
c.pack()
width height = tk.getint(c[‘width‘]) tk.getint(c[‘height‘])
pegwidth = 10
pegheight = height/2
pegdist = width/3
x1 y1 = (pegdist-pegwidth)/2 height/3
x2 y2 = x1+pegwidth y1+pegheight
self.pegs = []
p = c.create_rectangle(x1 y1 x2 y2 fill=‘black‘)
self.pegs.append(p)
x1 x2 = x1+pegdist x2+pegdist
p = c.create_rectangle(x1 y1 x2 y2 fill=‘black‘)
self.pegs.append(p)
x1 x2 = x1+pegdist x2+pegdist
p = c.create_rectangle(x1 y1 x2 y2 fill=‘black‘)
self.pegs.append(p)
self.tk.update()
pieceheight = pegheight//16
maxpiecewidth = pegdist*2//3
minpiecewidth = 2*pegwidth
self.pegstate = [[] [] []]
self.pieces = {}
x1 y1 = (pegdist-maxpiecewidth)//2 y2-pieceheight-2
x2 y2 = x1+maxpiecewidth y1+pieceheight
dx = (maxpiecewidth-minpiecewidth) // (2*max(1 n-1))
for i in range(n 0 -1):
p = c.create_rectangle(x1 y1 x2 y2 fill=‘red‘)
self.pieces[i] = p
self.pegstate[0].append(i)
相关资源
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
- Python 3.5.2 中文文档 互联网唯一CHM版本
- python3.5.2.chm官方文档
评论
共有 条评论