나는 스도쿠 퍼즐 생성기를위한 9x9 격자를 만들었습니다. 지금까지 프레임의 첫 번째 행에 대해 9 개의 변수를 작성했으며 9 개의 변수 그리드 행/열을 지정했습니다. 내가 사용하고있는 코드는 다음과 같습니다.9x9 그리드를보다 효율적으로 만드는 방법은 무엇입니까? (Python, Tkinter)
그리드에 대해 81 개의 셀을 만들어야하기 때문에보다 효율적인 방법이 필요합니다. 어떻게하면보다 효율적으로/더 잘할 수 있습니까? 도와주세요!
번호 :
from tkinter import *
root = Tk()
root.title('Sudoku')
root.geometry('1000x1000')
# create all of the main containers
center = Frame(root, bg='white', width=900, height=900, padx=3, pady=3)
# layout all of the main containers
root.grid_rowconfigure(9, weight=1)
root.grid_columnconfigure(9, weight=1)
center.grid(row=1, sticky="nsew")
# create the center widgets
center.grid_rowconfigure(0, weight=1)
center.grid_columnconfigure(1, weight=1)
cell1 = Frame(center, bg='white', highlightbackground="black", highlightcolor="black", highlightthickness=1, width=100, height=100, padx=3, pady=3)
cell2 = Frame(center, bg='white', highlightbackground="black", highlightcolor="black", highlightthickness=1, width=100, height=100, padx=3, pady=3)
cell3 = Frame(center, bg='white', highlightbackground="black", highlightcolor="black", highlightthickness=1, width=100, height=100, padx=3, pady=3)
cell4 = Frame(center, bg='white', highlightbackground="black", highlightcolor="black", highlightthickness=1, width=100, height=100, padx=3, pady=3)
cell5 = Frame(center, bg='white', highlightbackground="black", highlightcolor="black", highlightthickness=1, width=100, height=100, padx=3, pady=3)
cell6 = Frame(center, bg='white', highlightbackground="black", highlightcolor="black", highlightthickness=1, width=100, height=100, padx=3, pady=3)
cell7 = Frame(center, bg='white', highlightbackground="black", highlightcolor="black", highlightthickness=1, width=100, height=100, padx=3, pady=3)
cell8 = Frame(center, bg='white', highlightbackground="black", highlightcolor="black", highlightthickness=1, width=100, height=100, padx=3, pady=3)
cell9 = Frame(center, bg='white', highlightbackground="black", highlightcolor="black", highlightthickness=1, width=100, height=100, padx=3, pady=3)
#create first row of grid
cell1.grid(row=0, column=0)
cell2.grid(row=0, column=1)
cell3.grid(row=0, column=2)
cell4.grid(row=0, column=3)
cell5.grid(row=0, column=4)
cell6.grid(row=0, column=5)
cell7.grid(row=0, column=6)
cell8.grid(row=0, column=7)
cell9.grid(row=0, column=8)
root.mainloop()
for 루프를 사용 하시겠습니까? 'i in range (81) : – Novel
좋은 질문이지만 다른 곳에서도 훌륭한 답이 있습니다. 중첩 목록 (Python) 또는 2 차원 배열 (tkinter)에 대한 자습서를 검색하십시오. Stack Overflow는 정액 프로그래밍 주제에 대한 자습서를위한 장소가 아닙니다. – Prune