python用Tkinter实现国际棋盘的绘制

from tkinter import *

# 显示国际棋盘

class CheckerBoard:

    def __init__(self): 

        windows = Tk()

        windows.title('Checker board')



        # 设置画布的大小为640 * 640的正方形

        canvas = Canvas(windows, width = 640, height = 640, bg = 'white')

        # 将canvas放入容器中

        canvas.pack()

        

        # 国际棋盘是8 * 8的黑白格子型的

        for i in range(8):

            # 其每个格子的大小为80 * 80, (x1, y1)(x2, y2)

            x1 = 0

            y1 = 0 + i * 80

            x2 = 80

            y2 = 80 + i * 80

            for j in range(8):

                if i % 2 == 0:

                    if j % 2 == 0:

                        canvas.create_rectangle(x1, x2, x2, y2)

                    else:

                        canvas.create_rectangle(x1, y1, x2, y2, fill = 'black')

                else:

                    if j % 2 == 0:

                   
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
tkinter 实现的五子棋UI界面 import tkinter as tk from tkinter import messagebox from chessboard import ChessBoard ChessBoard = ChessBoard() class GUI(object): def __init__(self): self.counter = 0 self.winner = 0 self.is_start = False self.is_surrender = False self.window = tk.Tk() # 窗口对象(首字母大写) self.window.title('Gobang') self.window.geometry('800x540') self.window.resizable(width = False, height = False) # 画布对象 棋盘 self.canvas = tk.Canvas(self.window, height = 540, width = 540) self.chessboard = tk.PhotoImage(file = 'Gobang_chessboard/chessboard.gif') self.blackpoint = tk.PhotoImage(file = 'Gobang_chessboard/blackpoint.gif') self.whitepoint = tk.PhotoImage(file = 'Gobang_chessboard/whitepoint.gif') self.canvas.create_image(0, 0, anchor = 'nw', image = self.chessboard) self.canvas.bind("", self.get_point) self.start_point = 10 # 起始点位置 self.step = 35 # 每个格子的跨度 self.canvas.place(x = 0, y = 0) # 标签对象 self.l_info = tk.Label(self.window, text = 'Not started', font=('Arial', 12), width = 25, height = 2) self.l_info.place(x = 545, y = 0) # 文本框对象 self.t = tk.Text(self.window, height = 15) self.t.place(x = 540, y = 40) # 按钮对象 self.f_header = tk.Frame(self.window, highlightthickness=0) self.b_start = tk.Button(self.f_header, text = 'start', command = self.start) self.b_restart = tk.Button(self.f_header, text = 'restart', command = self.restart) self.b_regret = tk.Button(self.f_header, text = 'regret', command = self.regret) self.b_surrender = tk.Button(self.f_header, text = 'surrender', command = self.surrender) self.f_header.place(x = 545, y = 250) self.b_start.pack(side='left', padx=10) self.b_restart.pack(side = 'left') self.b_surrender.pack(side = 'right') self.b_regret.pac

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值