0

As someone who is relatively new to coding, I am trying to create my own chess game. Currently, I am facing a challenge in attempting to make my buttons invisible while still allowing them to execute piece movements. Any advice or guidance would be greatly appreciated. Thank you in advance for your assistance. Here's my Background and these are my button.

from tkinter import *
import tkinter as tk
from PIL import Image, ImageTk

# create object
window = Tk()
# Adjust the size
window.geometry('500x500')
# title
window.title('ChessBoard')
# import image
icon = PhotoImage(file='Board.png')
image = Image.open('Board.png')
# make icon
window.iconphoto(True, icon)
# resize image
resize_image = image.resize((430, 450))
img = ImageTk.PhotoImage(resize_image)

# create label and add resize image
label1 = Label(image= img)
label1.image = img
label1.pack()

# Making my buttons
list_box = {}
for x in range(8):
    label1.columnconfigure(x, weight=1)
    for y in range(8):

        list_box['box{0}{1}'.format(x, y)]= tk.Button(label1, height=3, width=6,)
        list_box['box{0}{1}'.format(x, y)].grid(row=x, column=y, padx=1, pady=1)
# start the main event loop
window.mainloop()

I've try to use this code but I kept getting this:

result

window.wm_attributes('-transparentcolor', '#2b9438')
list_box['box{0}{1}'.format(x, y)] = tk.Button(label1, height=3, width=6, bg='#2b9438')
2
  • Why don't you just using buttons with different background colors to simulate the board? Commented Apr 2, 2023 at 14:41
  • Thanks for the advice. That's mostly likely the best option right now. I thought that there would be a quick simpler solution. Commented Apr 2, 2023 at 17:40

1 Answer 1

-1

It’s great that you’re working on your own chess game! To make your buttons invisible while still allowing them to execute piece movements, you can use the pack_forget() method.

This method is generally used to unmap widgets from the window. You can also use the lift() and lower() methods to change the stacking order of widgets. The net effect is that you can hide widgets behind sibling widgets (or descendants of siblings). When you want them to be visible you lift them, and when you want them to be invisible you lower them. I hope this helps! Also, here are some resources that might help you with your chess game:

Python Chess - pygame

Chess Game in Tkinter

How to Code a Simple Chess Game in Python

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.