使用 python tkinter,如何使按钮不可见?

问题描述 投票:0回答:0

作为一个刚接触编码的人,我正在尝试创建自己的国际象棋游戏。目前,我面临着一个挑战,试图让我的按钮不可见,同时仍然允许它们执行棋子动作。任何建议或指导将不胜感激。预先感谢您的协助。这是我的Background,这些是我的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()

我尝试使用此代码,但我一直得到 this .

window.wm_attributes('-transparentcolor', '#2b9438') list_box['box{0}{1}'.format(x, y)]= tk.Button(label1, height=3, width=6, bg='#2b9438')

python tkinter tkinter-layout tkinter-button python-chess
© www.soinside.com 2019 - 2024. All rights reserved.