I have a square of labels that make a scrabble board. (link to picture)
Code to generate:
colors = {"TWS":"red", "DWS":"pink", "TLS":"light green", "DLS":"light blue", "*":"pink"}
self.boardFrame = Frame(self.root, bd=1, relief=SUNKEN)
self.boardFrame.place(x=50, y=50, width=497, height = 497)
labels = list()
squares = list()
for i in range(16):
for j in range(16):
label = self.board[j][i]
if label in self.extraList:
entry = Frame(self.boardFrame, bd=1, relief=RAISED)
entry.place(x=(i*31), y=(j*31), width=31, height=31)
labels.append(func.Label(entry, text = label,
height = 31, width = 31))
if label in colors.keys():
labels[-1].config(bg=colors[label])
labels[-1].pack()
I would like to make it able to zoom in when the user clicks it. I have heard that you could use something like canvas
. I have looked at this question but I did not understand it particularly. If I had a image for each type of square (which is possible), how could I efficiently resize every label? Something like:
def zoom(self, event):
if math.isclose(event.x, self.x, abs_tol=self.boardWidth/2) and \
math.isclose(event.y, self.y, abs_tol=self.boardHeight/2):
self.height += 30
self.width += 30
self.x -= event.x
self.y -= event.y
self.label.config(height=self.height, width=self.width)
self.label.place_configure(x = self.x, y = self.y)
I'm not sure. Any help would be welcome really. Thanks.
EDIT: When I say zoom, I mean actually zoom in. For example, zooming in 2x will only have 1/4 of the labels visible, and they will each be twice as big.
EDIT: by the way all of the code is in the tiles.py
in this github repo.