首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用tkinter GUI python创建9*9数独生成器?

如何使用tkinter GUI python创建9*9数独生成器?
EN

Stack Overflow用户
提问于 2018-07-19 19:12:08
回答 0查看 1.8K关注 0票数 1

如何使用python和tkinter创建9*9数独生成器?如何将其生成到gui?

我尝试了这些:

代码语言:javascript
复制
import random
numbers = [1,2,3,4,5,6,7,8,9]

def reg():
    def makeBoard():
         board = None
         while board is None:
         board = attemptBoard()
         return board

def attemptBoard():
    board = [[None for _ in range(9)] for _ in range(9)]
    for i in range(9):
        for j in range(9):
            checking = numbers[:]
            random.shuffle(checking)
            x = -1
            loopStart = 0
            while board[i][j] is None:
                x += 1
                if x == 9:

                    return None
                checkMe = [checking[x],True]
                if checkMe in board[i]:

                    continue
                checkis = False
                for checkRow in board:
                    if checkRow[j] == checkMe:

                        checkis = True
                if checkis: continue

                if i % 3 == 1:
                    if   j % 3 == 0 and checkMe in (board[i-1][j+1],board[i-1][j+2]): continue
                    elif j % 3 == 1 and checkMe in (board[i-1][j-1],board[i-1][j+1]): continue
                    elif j % 3 == 2 and checkMe in (board[i-1][j-1],board[i-1][j-2]): continue
                elif i % 3 == 2:
                    if   j % 3 == 0 and checkMe in (board[i-1][j+1],board[i-1][j+2],board[i-2][j+1],board[i-2][j+2]): continue
                    elif j % 3 == 1 and checkMe in (board[i-1][j-1],board[i-1][j+1],board[i-2][j-1],board[i-2][j+1]): continue
                    elif j % 3 == 2 and checkMe in (board[i-1][j-1],board[i-1][j-2],board[i-2][j-1],board[i-2][j-2]): continue

                board[i][j] = checkMe
    return board
a=makeBoard()

我使用这些代码创建了一个9*9数独,但是我如何才能将它应用于gui。所以请帮我创建一个图形用户界面。带有重新生成按钮和关闭按钮。我想要一个好看的窗户。

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51421185

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档