I have set up a series of entries that change the colors of a canvas object in tkinter. While the print yielded results, it did not change the colors of said object in the canvas, making me wonder what did I do wrong in calling the Chara1
and/or ChangeVar
functions.
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
frame = tk.Frame(root)
frame.pack()
#Name = tk.Frame(Frame)
#Name.pack(side = Side)
TabTool = tk.Frame(root)
TabTool.pack(side = tk.TOP)
Bottom = tk.Frame(root)
Bottom.pack(side = tk.BOTTOM)
RightSide = tk.Frame(Bottom)
RightSide.pack(side = tk.RIGHT)
def Label(Frame, Name, Text):
Name = tk.Label(Frame, text = Text)
Name.pack(side = tk.LEFT)
def GL(Frame, Text, Grid):
tk.Label(Frame, text=Text).grid(row=Grid)
def Button(Frame, Name, Text, Image, Command, Pack):
Name = tk.Button(Frame, text = Text, image = Image, command = Command)
Name.pack(side = Pack)
CanvasArea = ttk.Frame(Bottom)
CanvasArea.pack(side = tk.LEFT)
CW = 300
CH = 600
LXM = (CW / 2)
LYM = (CH / 2)
GL(RightSide, "Color 1:", 0)
Color1 = tk.Entry(RightSide)
Color1.grid(row=0, column=1)
GL(RightSide, "Color 2:", 1)
Color2 = tk.Entry(RightSide)
Color2.grid(row=1, column=1)
GL(RightSide, "Color 3:", 6)
Color3 = tk.Entry(RightSide)
Color3.grid(row=6, column=1)
ACI = tk.StringVar(RightSide, '1CI', 'red')
BCI = tk.StringVar(RightSide, '2CI', 'green')
CCI = tk.StringVar(RightSide, '3CI', 'black')
MainCanvas = tk.Canvas(CanvasArea, bg = 'white', height = CH, width = CW)
MainCanvas.pack(side = tk.LEFT)
class C1:
LX = LXM
LY = LYM
SX = 1
SY = 1
HL = 0
SL = 0
#None
NP = (((-1 * SX) + LX), ((0 * SY) + LY), ((1 * SX) + LX), ((0 * SY) + LY))
#Shapes
A1 = (((10 * SX) + LX), ((0 * SY) + LY), ((10 * SX) + LX), ((0 * SY) + LY)), ((10 * SX) + LX), ((-10 * SY) + LY)
A2 = (((-10 * SX) + LX), ((0 * SY) + LY), ((-10 * SX) + LX), ((0 * SY) + LY)), ((10 * SX) + LX), ((10 * SY) + LY)
def Chara1(AT, BT, CT, MC1, MC2, MC3, LC, LT, LS)
def Main(PI, MC, LO, LT, LS):
MainCanvas.create_polygon(PI, fill = MC, outline = LO, width = LT, smooth = LS)
Main(AT, MC1, LC, LT, LS)
Main(BT, MC2, LC, LT, LS)
Main(CT, MC3, LC, LT, LS)
Chara1(C1.A1, C1.A2, C1.NP, 1CI, 2CI, None, 3CI, 5, 0)
def ChangeVar():
ACI = tk.StringVar(RightSide, 'ACI', Color1.get())
BCI = tk.StringVar(RightSide, 'BCI', Color2.get())
CCI = tk.StringVar(RightSide, 'CCI', Color3.get())
print(ACI)
print(BCI)
print(CCI)
Button(Bottom , 'UC', 'UpdateColors', None, ChangeVar, tk.LEFT)
I tried using a lambda command (tk.Button(Bottom , text = 'UM', command=lambda *args: Chara1(C1.A1, C1.A2, C1.NP, ACI, BCI, None, CCI, 5, 0)).pack()
) to ‘refresh’ the function call by reassigning them, but failed (no color change). What should I do?
Bonus Question: Is it possible to use the same method with the shape variables from the C1 class to change the shape in Chara1 (by changing input in the T (1T, 2T, 3T) arguments to different inputs)?