您好,欢迎光临本网站![请登录][注册会员]  
文件名称: 用tkinter 实现的五子棋UI界面
  所属分类: 其他
  开发工具:
  文件大小: 5kb
  下载次数: 0
  上传时间: 2019-06-06
  提 供 者: qq_43******
 详细说明: 用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.pack(side = right, padx=10) self.window.mainloop() # 循环显示 # 转换坐标 def get_point(self, e): x, y = int((e.x - self.start_point) / self.step), int((e.y - self.start_point) / self.step) print([x, y]) self.info() if self.is_start is True and self.is_surrender is False: self.put_chess(x, y) # 下棋 def put_chess(self, x, y): x_p, y_p = int((x * self.step) + self.start_point + 15), int((y * self.step) + self.start_point + 15) if self.counter % 2 == 0: ChessBoard.draw_xy(x, y, state = 1) self.canvas.create_image(x_p, y_p, anchor = center, image = self.blackpoint) self.winner = ChessBoard.anyone_win(x, y) self.info() self.counter += 1 else: ChessBoard.draw_xy(x, y, state = 2) self.canvas.create_image(x_p, y_p, anchor = center, image = self.whitepoint) self.winner = ChessBoard.anyone_win(x, y) self.info() self.counter += 1 # 提示语 def info(self): if self.is_start is True and self.is_surrender is False: if self.counter % 2 == 1: self.l_info.config(text = Turn for black) else: self.l_info.config(text = Turn for white) if self.winner != 0: self.is_start = False if self.winner == 1: self.l_info.config(text = black win) else: self.l_info.config(text = white win) # 开始 def start(self): self.is_start = True self.l_info.config(text = Turn for black) # 重来 def restart(self): self.canvas.create_image(0, 0, anchor = nw, image = self.chessboard) ChessBoard.reset() self.counter = 0 self.winner = 0 self.is_start = True self.is_surrender = False self.l_info.config(text = Turn for black) # 悔棋 def regret(self): if self.counter != 0: pass # 认输 def surrender(self): if self.is_start is True and self.counter != 0: self.is_surrender = True if self.counter % 2 == 0: self.l_info.config(text = black gives up) else: self.l_info.config(text = white gives up) if __name__ == __main__: GUI = GUI() print(ChessBoard.board())
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索:
 输入关键字,在本站1000多万海量源码库中尽情搜索: