tkinter canvas项目配置

问题描述

| 我正在尝试制作一个骰子对象,并且希望能够控制点子的颜色。我用黑色填充创建了点,然后尝试使用将其更改为红色
self.canvas.itemconfigure(self.pip1,fill=\'red\') 
但这似乎没有效果。没有错误,所以我想知道为什么未显示更改。 最低工作示例:
from tkinter import *
from tkinter import ttk

class Dice:
    #the x and y instancing variables are for the x and y coordinates of the top left corner of the rectangle
    def __init__(self,win,x,y):
        self.win = win
        self.win.geometry(\"500x500\")
        self.canvas = Canvas(self.win)
        self.canvas.place(x=0,y=0)

        die = self.canvas.create_rectangle(x,y,x+88,y+88,fill=\'white\',width=1)
        offset = 20

        #create 7 circles for pip locations:

        self.pip1 = self.pips(x+offset,y+offset)
        self.pip2 = self.pips(x+offset,y+2*offset)
        self.pip3 = self.pips(x+offset,y+3*offset)
        self.pip4 = self.pips(x+2*offset,y+2*offset)
        self.pip5 = self.pips(x+3*offset,y+offset)
        self.pip6 = self.pips(x+3*offset,y+2*offset)
        self.pip7 = self.pips(x+3*offset,y+3*offset)

        self.canvas.itemconfigure(self.pip1,fill=\'red\')

    def pips(self,y):
        pip = self.canvas.create_oval(x,x+9,y+9,fill=\'black\',width=0)

    #def setValue(self,value)

    #def pipsOff(self,pip):



def test():
    x = Dice(Tk(),50,50)
    mainloop()
    

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)