我试图建立一个国际象棋游戏在Python使用tkinter的图形。我创建了一个8x8(行和列)的网格,并将瓷砖放在那里(这是一种按钮)。这一切都很好,直到你用棋子填满整行,然后整行消失。我不知道为什么。
当填充整行时,除了一个:https://gyazo.com/865aed481e4a84c5e9e8918695410006
填充整行时:https://gyazo.com/acf48c9790335ba11913b6017d2652c3
如您所见,将显示整行按钮^
这是我的密码:
平铺类的代码(继承tkinter按钮)
class Tile(tk.Button):
piece = None
imageLocation = {"bb":"./img/blackBishop.gif",
"bk":"./img/blackKing.gif",
"bh":"./img/blackHorse.gif",
"bp":"./img/blackPawn.gif",
"bq":"./img/blackQueen.gif",
"br":"./img/blackRook.gif",
"wb":"./img/whiteBishop.gif",
"wk":"./img/whiteKing.gif",
"wh":"./img/whiteHorse.gif",
"wp":"./img/whitePawn.gif",
"wq":"./img/whiteQueen.gif",
"wr":"./img/whiteRook.gif",
}
def __init__(self, master, *args, **kwargs):
super(Tile, self).__init__(master, *args, **kwargs)
def addPiece(self, pieceName):
self.piece = pieceName
im = Image.open(self.imageLocation[pieceName])
photo = ImageTk.PhotoImage(im)
self.image = photo
self.config(image=photo)
主类的代码:
def main():
root = tk.Tk()
root.title("Chess in Python using tkinter")
root.geometry("640x640")
root.resizable(False, False)
board = Board(root)
root.mainloop()
if __name__ == "__main__":
main()
董事会代码:
class Board(tk.Frame):
move = 0 #
# Columns and rows
columns = 8
rows = 8
# Size of a square
square = 75
# A dictionary containing all the tiles
board = np.empty((8, 8), dtype=Tile)
def __init__(self, master, *args, **kwargs):
super(Board, self).__init__(master, *args, **kwargs)
self.master = master
self.draw_board()
self.initialPlacement()
def draw_board(self):
grey = "#7d827e"
# Create the grid
self.master.columnconfigure((0, 1, 2, 3, 4, 5, 6, 7), weight=1)
self.master.rowconfigure((0, 1, 2, 3, 4, 5, 6, 7), weight=1)
# Create the tiles (as buttons)
for row in range(self.rows):
for col in range(self.columns):
num = row + col
if num % 2 == 0:
self.board[row][col] = Tile(self.master, bg="white", highlightbackground="white", height=self.square,
width=self.square, borderwidth=0)
else:
self.board[row][col] = Tile(self.master, bg=grey, highlightbackground=grey, height=self.square,
width=self.square, borderwidth=0)
self.board[row][col].grid(row=row, column=col)
def addPiece(self, piece, row, col):
tile = self.board[row][col]
tile.addPiece(piece)
def initialPlacement(self):
initialArray = [
["br", "bh", "bb", "bq", "bk", "bb", "bh", "br"],
["bp", "bp", "bp", "bp", "bp", "bp", "bp", "bp"],
[" ", " ", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", " ", " "],
[" ", " ", " ", " ", " ", " ", " ", " "],
["wp", "wp", "wp", "wp", "wp", "wp", "wp", "wp"],
["wr", "wh", "wb", "wq", "wk", "wb", "wh", "wr"],
]
for row in range(self.rows):
for col in range(self.columns):
piece = initialArray[row][col]
if piece != " ": #TODO
self.addPiece(piece, row, col)
添加minsize=self。方形到行和列的配置解决了这个问题。
问题内容: 我正在尝试使用Javafx制作屏幕键盘。我正在使用Scene Builder制作FXML文件。 但是,当调整窗口大小时,内容不会。我希望按钮增加/减小大小,直到适合窗口为止。启用Hgrow和Vgrow无效。 而且我找不到如何在按钮上设置填充。我想使类似Ctrl的按钮更小而不丢失文本。 问题答案: 根据字体大小调整大小 对于您的特定情况,而不是尝试使用填充或其他布局约束来调整按钮的大小,
我想在一行中用n个整数填充一个列表,我试过了,但如何增加n的限制?
我正在比较填充整数列表所需的时间与整数向量。 每个矢量 令我惊讶的是,填充列表比填充整数向量快100倍。我希望填充整数的向量要快得多,因为向量在内存中是连续的,插入要快得多。 填充列表怎么会比填充向量快100倍而不是10倍呢?我肯定我缺少一些导致这种情况的概念或想法。 这是我用来生成结果的代码 有人能给我解释一下为什么会这样吗???
使用LeftBarItems和RightBarItems时,我遇到过过多的UIBarButtonItem填充/间距(请参见下图)。UIBarButtonims上使用的图标不包含额外的填充。我想知道是什么原因造成的?
我有一个调查,有一堆问题,包括实际问题,一些是或否的单选按钮和一个评论框。我加了一张照片给你看。下面是填充问题后的html结构。 此信息通过web服务和jquery动态填充。看起来这些问题是动态填充的,每个问题都包含相同的类名、范围名等。有40多个问题被附加到div中。 我想做的是选择一个特定的问题并选中一个特定的单选按钮。然后,如果单击某个单选按钮,则会自动选中其他单选按钮。我相信Jquery是