python好玩儿代码

这篇博客介绍了两个使用Python实现的趣味项目:一个是井字棋游戏,适合双人对战;另一个则是模拟电脑运行,可以通过任务管理器进行控制。这两个项目展示了Python在开发交互式应用方面的潜力。
摘要由CSDN通过智能技术生成

1.井字棋

 注意,这个不是人工,需要两个人对战。

from tkinter import *
import tkinter.messagebox as msg
 
root = Tk()
root.title('TIC-TAC-TOE---Project Gurukul')
# labels
Label(root, text="player1 : X", font="times 15").grid(row=0, column=1)
Label(root, text="player2 : O", font="times 15").grid(row=0, column=2)
 
digits = [1, 2, 3, 4, 5, 6, 7, 8, 9]
 
# for player1 sign = X and for player2 sign= Y
mark = ''
 
# counting the no. of click
count = 0
 
panels = ["panel"] * 10
 
 
def win(panels, sign):
    return ((panels[1] == panels[2] == panels[3] == sign)
            or (panels[1] == panels[4] == panels[7] == sign)
            or (panels[1] == panels[5] == panels[9] == sign)
            or (panels[2] == panels[5] == panels[8] == sign)
            or (panels[3] == panels[6] == panels[9] == sign)
            or (panels[3] == panels[5] == panels[7] == sign)
            or (panels[4] == panels[5] == panels[6] == sign)
            or (panels[7] == panels[8] == panels[9] == sign))
 
 
def checker(digit):
    global count, mark, digits
 
    # Check which button clicked
 
    if digit == 1 and digit in digits:
        digits.remove(digit)
        ##player1 will play if the value of count is even and for odd player2 will play
        if count % 2 == 0:
            mark = 'X'
            panels[digit] = mark
        elif count % 2 != 0:
            mark = 'O'
            panels[digit] = mark
 
        button1.config(text=mark)
        co
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值