日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python tkinter button颜色变不了_tkinter多按钮颜色变化

發布時間:2023/12/9 python 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python tkinter button颜色变不了_tkinter多按钮颜色变化 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我使用tkinter創建一個8x8按鈕矩陣,當按下單個按鈕時,它會添加到最終列表中(例如finalList=((0,0),(5,7),(6,6),…),允許我快速創建8x8(x,y)坐標圖像。我已經創建了一個帶有按鈕的窗口,但是現在嘗試在一個函數中引用這些按鈕以添加到列表中甚至更改按鈕的顏色時出現問題

我已經讀到,一旦按鈕被創建,你創建了另一個,它將移動到按鈕引用。我懷疑我需要使用dict或2D數組來存儲所有這些按鈕的引用,但我正在努力尋找解決方案。在from tkinter import *

class App:

def updateChange(self):

'''

-Have the button change colour when pressed

-add coordinate to final list

'''

x , y = self.xY

self.buttons[x][y].configure(bg="#000000")

def __init__(self, master):

frame = Frame(master)

frame.pack()

self.buttons = [] # Do I need to create a dict of button's so I can reference the particular button I wish to update?

for matrixColumn in range(8):

for matrixRow in range(8):

self.xY = (matrixColumn,matrixRow)

stringXY = str(self.xY)

self.button = Button(frame,text=stringXY, fg="#000000", bg="#ffffff", command = self.updateChange).grid(row=matrixRow,column=matrixColumn)

self.buttons[matrixColumn][matrixRow].append(self.button)

root = Tk()

app = App(root)

root.mainloop()

總結

以上是生活随笔為你收集整理的python tkinter button颜色变不了_tkinter多按钮颜色变化的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。