资源简介
python写了个自动拼图游戏,内部算法使用的是A*算法。
代码片段和文件信息
# -*- coding:utf-8 -*-
import sys
from tkinter import *
from tkinter import filedialog
from tkinter import ttk
from PIL import Image ImageTk
import random
import math
import time
def callback1():#打开图片
global fpath
fpath = filedialog.askopenfilename();
v1.set(fpath)
# print(fpath)
def callback2():#开始
global entry_num
entry_num=e1.get();#print(“e1“ entry_num)
root1.withdraw()
root = Toplevel()
im0 = Image.open(fpath)
# print(im0.size[0])
image_x=im0.size[0];image_y=im0.size[1]
if (image_x<800)|(image_y<500)|(image_x>1000)|(image_y>650):
min_xy=min(650/image_y1000/image_x)
image_x = int(image_x*min_xy)
image_y = int(image_y*min_xy)
im0 = im0.resize((image_ximage_y))
im0 = fill_image(im0 m n)
im0=cut_image(im0 m nentry_num)
global im
im=[]
for i in range(0m*n):im.append(ImageTk.PhotoImage(image=im0[i]))
# print(‘im‘im.width()image_x)
root.title(‘拼图游戏‘)
root.geometry(‘%dx%d‘ % (image_x+200 650)) # 这里的乘号不是 * ,而是小写英文字母 x
# root.resizable(width=Falseheight=False)
# photo = PhotoImage(file=“timg.jpg“)
btn1 = Button(root text=‘打乱图片‘ command=callback3) #
btn1.place(x=image_x+100 y=40 width=80 height=50)
# btn1.pack(ipadx=20 ipady=10padx=10 pady=10)
btn2 = Button(root text=‘开始重排‘ command=run) # 1command=root.quit()
btn2.place(x=image_x+100 y=110 width=80 height=50)
btn3 = Button(root text=‘退出‘ command=sys.exit) # command=root.withdraw()
btn3.place(x=image_x+100 y=180 width=80 height=50)
#********************************************************
global xsizeysizeframe1imageI
xsizeysize=im0[0].size
# print(xsizeysize)
frame1 = frame(rootheight = ysize*nwidth =xsize*m)
imageI=[]
for j in range(0n):
for i in range(0 m):
imageI.append(IntVar())
imageI[j*m+i]=Label(frame1 image=im[j*m+i]relief=‘groove‘borderwidth=5)
imageI[j*m+i].grid(column=irow=j)
frame1.place(x=10 y=(650-image_y)/2)
# ********************************************************
frame1.mainloop()
def callback3():#打乱图片
global move
global li0
global li_goal
move = [-m m -1 1]
li_goal=list(range(1 m*n+1))
# entry_num=int(entry_num)
li_goal[int(entry_num)-1]=0
li0=set_zero(int(entry_num) li_goal)
print(‘li0‘li0)
# path_ = askopenfilename()
# path.set(path_)
# img_open = Image.open(e1.get())
# img = ImageTk.PhotoImage(img_open)
for j in range(0n):
for i in range(0 m):
temp=li0[j*m+i]-1
if temp<0:temp=int(entry_num)-1
imageI[j*m+i].config(image=im[temp])
imageI[j*m+i].image = im[temp]
def run():
mc = run_Axing()
global step
if mc > -1:
num = 0
step = [openList[mc]]
while mc > 0:
相关资源
- 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的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
评论
共有 条评论