在下面的代码中,我试图删除画布的边框或画布位于每个单元格内的框架的边缘,但是,我分别为框架和画布设置了 bd=0 和 borderwidth=0并将它们的颜色设置为与背景颜色相同,但仍然没有成功。以前有人经历过这种情况吗?我使用在线 IDE Replit,因此如果有人运行它,我事先对布局表示歉意,但我也有兴趣知道这是否会产生影响。 谢谢
import tkinter as tk
from tkinter import messagebox as m
WOODEN="#BA8C63"
PALE_BLUE="#CDF5F6"
PALE_YELLOW="#EFF9DA"
PALE_RED="#F9D8D6"
PALE_GREEN="#DDF0C7"
PALE_PINK="#D6CDEA"
class Game(tk.Tk):
def __init__(self):
super().__init__()
self.geometry("975x210")
self.configure(bg=WOODEN)
self.resizable(False, False)
self.title("Mancala")
self.P1pits={"Bank":Bank(self,"P1"),"Pits":[Pit(self,"P1",i) for i in range(1,9)]}
self.P2pits={"Bank":Bank(self,"P2"),"Pits":[Pit(self,"P2",i) for i in range (1,9)]}
self.mainloop()
class Cell(tk.Frame):
def __init__(self,master,height,BG):
super().__init__(master=master,width=80,height=height,bg=BG,borderwidth=0)
self.amount=0
self.start_canvas()
self.redraw()
def start_canvas(self):
self.canv=tk.Canvas(self,width=80,height=80,bg=WOODEN,bd=0)
def redraw(self):
self.canv.pack()
class Bank(Cell):
def __init__(self,master,player):
super().__init__(master,148,WOODEN)
self.player=player
self.counters=[]
self.enlarge_canvas()
self.add_pot()
if player == "P1":
self.grid(row=0,column=9,rowspan=2,pady=(7,10),padx=(10,15))
else:
self.grid(row=0,column=0,rowspan=2,pady=(10,7),padx=(15,10))
def enlarge_canvas(self):
self.canv.configure(height=180)
def add_pot(self):
self.p1=self.canv.create_arc((2,2,78,78),start=0,extent=180)
self.p2=self.canv.create_arc((2,102,78,178),start=180,extent=180)
self.p3=self.canv.create_line(2,40,78,40,fill=WOODEN)
self.p4=self.canv.create_line(2,140,78,140,fill=WOODEN)
self.p5=self.canv.create_line(2,40,2,140)
self.p6=self.canv.create_line(78,40,78,140)
class Pit(Cell):
def __init__(self,master,player,index):
super().__init__(master,80,WOODEN)
self.amount=6
self.counters=[]
self.add_pot()
if player == "P1":
self.grid(row=1,column=index,pady=(7,12),padx=4)
else:
self.grid(row=0,column=9-index,pady=(12,7),padx=4)
def add_pot(self):
self.p1=self.canv.create_oval(1,1,79,79)
def again(val):
global window
window.destroy()
if val:
window = Game()
if __name__ == "__main__":
window = Game()
创建画布时需要设置
highlightthickness=0
:
def start_canvas(self):
self.canv=tk.Canvas(self,width=80,height=80,bg=WOODEN,bd=0,highlightthickness=0)