# -*- coding: utf-8 -*-

# bulid by Bean_Wei/ 2017/12/07 22:17

from Tkinter import *

import tkMessageBox

root=Tk()

root.title("X O")

#棋盘现况

chessboard=['','','','','','','','','']

#胜局数组

winchess=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]

#判断胜负

def judge():

w=0

for c in chessboard:

if c!='':

w+=1

return w

if w!=0:

for win in range(0,len(winchess)):

if chessboard[winchess[win][0]]==chessboard[winchess[win][1]]==chessboard[winchess[win][2]]:

tkMessageBox.showinfo(title='结果', message='%s胜'%chessboard[winchess[win][0]])

elif w==9:

tkMessageBox.showinfo(title='结果', message='平局')

else:

continue

#更新棋盘 ,先手为“X”后手为“O”

def rebtn_1():

num=0

for i in chessboard:

if i=='':

num+=1

if (num % 2)==0:

button_1['text']='O'

else:

button_1['text']='X'

button_1['state']='disabled'

chessboard[0]=button_1['text']

judge()

def rebtn_2():

num=0

for i in chessboard:

if i=='':

num+=1

if (num % 2)==0:

button_2['text']='O'

else:

button_2['text']='X'

button_2['state']='disabled'

chessboard[1]=button_2['text']

judge()

def rebtn_3():

num=0

for i in chessboard:

if i=='':

num+=1

if (num % 2)==0:

button_3['text']='O'

else:

button_3['text']='X'

button_3['state']='disabled'

chessboard[2]=button_3['text']

judge()

def rebtn_4():

num=0

for i in chessboard:

if i=='':

num+=1

if (num % 2)==0:

button_4['text']='O'

else:

button_4['text']='X'

button_4['state']='disabled'

chessboard[3]=button_4['text']

judge()

def rebtn_5():

num=0

for i in chessboard:

if i=='':

num+=1

if (num % 2)==0:

button_5['text']='O'

else:

button_5['text']='X'

button_5['state']='disabled'

chessboard[4]=button_5['text']

judge()

def rebtn_6():

num=0

for i in chessboard:

if i=='':

num+=1

if (num % 2)==0:

button_6['text']='O'

else:

button_6['text']='X'

button_6['state']='disabled'

chessboard[5]=button_6['text']

judge()

def rebtn_7():

num=0

for i in chessboard:

if i=='':

num+=1

if (num % 2)==0:

button_7['text']='O'

else:

button_7['text']='X'

button_7['state']='disabled'

chessboard[6]=button_7['text']

judge()

def rebtn_8():

num=0

for i in chessboard:

if i=='':

num+=1

if (num % 2)==0:

button_8['text']='O'

else:

button_8['text']='X'

button_8['state']='disabled'

chessboard[7]=button_8['text']

judge()

def rebtn_9():

num=0

for i in chessboard:

if i=='':

num+=1

if (num % 2)==0:

button_9['text']='O'

else:

button_9['text']='X'

button_9['state']='disabled'

chessboard[8]=button_9['text']

judge()

#创建棋盘

button_1=Button(root,width=13,height=5,cursor='hand2')

button_1['text']=''

button_1['command']=rebtn_1

button_1.grid(row=0,column=0)

button_2=Button(root,width=13,height=5,cursor='hand2')

button_2['text']=''

button_2['command']=rebtn_2

button_2.grid(row=0,column=1)

button_3=Button(root,width=13,height=5,cursor='hand2')

button_3['text']=''

button_3['command']=rebtn_3

button_3.grid(row=0,column=2)

button_4=Button(root,width=13,height=5,cursor='hand2')

button_4['text']=''

button_4['command']=rebtn_4

button_4.grid(row=1,column=0)

button_5=Button(root,width=13,height=5,cursor='hand2')

button_5['text']=''

button_5['command']=rebtn_5

button_5.grid(row=1,column=1)

button_6=Button(root,width=13,height=5,cursor='hand2')

button_6['text']=''

button_6['command']=rebtn_6

button_6.grid(row=1,column=2)

button_7=Button(root,width=13,height=5,cursor='hand2')

button_7['text']=''

button_7['command']=rebtn_7

button_7.grid(row=2,column=0)

button_8=Button(root,width=13,height=5,cursor='hand2')

button_8['text']=''

button_8['command']=rebtn_8

button_8.grid(row=2,column=1)

button_9=Button(root,width=13,height=5,cursor='hand2')

button_9['text']=''

button_9['command']=rebtn_9

button_9.grid(row=2,column=2)

root.resizable(width='false',height='false')

root.mainloop()

python井字棋如何判断输赢_python 井字棋游戏 简单版,不知道为什么不判断,用Tkinter做的界面...相关推荐

  1. python井字棋如何判断输赢_Python|找出井字棋的获胜者

    井字棋游戏的规则如下: 玩家轮流将棋子放在空方格 (" ") 上. 第一个玩家 A 总是用 "X" 作为棋子,而第二个玩家 B 总是用 "O" ...

  2. python井字棋如何判断输赢_井字棋判断输赢的两种方法

    //方法一 public static int IsSolved(int[,] b) { var c012 = new int[] { 0, 1, 2 }; var s = string.Join(& ...

  3. python井字棋最大最小算法_python井字棋算法及代码

    井字棋盘看起来像一个大的井字符号(#),有9 个空格,可以包含X.O 或 关于落子问题 由于只能采用键盘输入,所以需要对棋盘进行坐标表示: 即直接用1-9个9个数字来表示位置, 7|8|9 -+-+- ...

  4. python实现文件上传预览_Python文件上传功能简单实现

    本文章代码上传在码云上 代码地址 git@gitee.com:DanYuJie/upanddown.git 这里我们使用flask框架,简单实用 目录结构: upandown/ static/ css ...

  5. python 获取值类型用于定义变量_Python中的变量和简单数据类型

    变量: 变量是存储在内存中的值,在创建变量时会在内存中开辟一个空间. 变量可以指定不同的数据类型,这些变量可以存储整数,小数或字符串. 基于变量的数据类型,解释器会分配指定内存,并决定什么数据可以被存 ...

  6. python实现有障碍物的贪吃蛇_python实现贪吃蛇游戏源码

    本文实例为大家分享了python实现贪吃蛇的具体代码,供大家参考,具体内容如下 import pygame import sys import random SCREEN_X=600 SCREEN_Y ...

  7. python递归求13的n次方_Python题目:递归的简单题目,求阶乘,求n-m的累积和,求斐波那契...

    递归 从前有座山,山里有座庙,庙里有个老和尚,正在给小和尚讲故事!故事是什么呢?从前有座山,山里有座庙- 定义:递归函数是自身直接或者间接调用自身并且有终止条件的函数 特点:将大问题分解成n个小问题, ...

  8. Python爬取哔哩哔哩弹幕并且造词云图简单版!!!

    一,操作步骤 1.通过浏览器打开哔哩哔哩 2.选择一个播放量较合适的视频(不要太大也不要太小 大概就50万的样子)比如我用的是:https://www.bilibili.com/video/BV1th ...

  9. 五子棋 判断输赢的函数

    /********************************************* //刚写了个控制台的五子棋游戏,发现判断输赢花了我不少时间,特意贴出来. //如果大家有更好的方法,欢迎共 ...

  10. python拿什么做可视化界面好-手把手教你用Python做个可视化的“剪刀石头布”小游戏...

    /1 前言/ 最近在学习PyQt5可视化界面,这是一个内容非常丰富的gui库,相对于tkinter库,功能更加强大,界面更加美观,操作也不难.于是我开始小试牛刀,用PyQt5做个可视化的"剪 ...

最新文章

  1. 从Qcheck 1.3 不能在不同操作系统上运行问题(chro124、chro342)说开来------
  2. 在线协作沟通,以目标分解成任务树基础的团队配合
  3. Android开源项目
  4. DCMTK:类DcmUnsigned64bitVeryLong的测试程序
  5. 白话AI:看懂深度学习真的那么难吗?初中数学,就用10分钟
  6. python 集合(set)
  7. Treap树堆(bzoj 3224: Tyvj 1728 普通平衡树)
  8. C语言:使用递归解决汉诺塔问题。
  9. 学习马士兵Java教程
  10. win10电脑wifi服务器未响应,Win10系统点击无线图标没反应的解决方法
  11. #GeekPoint# 苹果的 AR 眼镜
  12. .NET Framework 3.5 安装错误:0x800F0906、0x800F081F、0x800F0907
  13. Layer 打开新页面
  14. 「JCVI」如何筛选得到最优blast比对结果?
  15. 测绘资质高性能数据服务器,测绘资质分级标准2020年
  16. heaps 和 priority queue堆和优先队列的定义和数据结构表示
  17. 关于TypeError: threshold must be numeric解决办法
  18. python 密码破解器
  19. 学术英语阅读与写作5:实验结果Result
  20. raid卡缓存对硬盘性能_我们怎么解决机械硬盘既慢又容易坏的问题

热门文章

  1. this与$(this)的区别
  2. rman异机恢复数据库
  3. EditPlus for python
  4. Reflector使用手记
  5. 17.Linux 高性能服务器编程 --- 系统检测工具
  6. 11.PHP memcache 与 memcached 区别
  7. 13.字符串,结构,联合
  8. mc服务器天赋系统,[娱乐|经济]GokiStats——全新的天赋系统插件MySQL可用[全版本]...
  9. css对大小写不敏感
  10. 如何从QC中导出测试用例及其测试步骤