after updating the list a OptionMenu uses it does not automatically update. I tried fixing this by implementing
Options['values'] = options
but I only get the error: "_tkinter.TclError: unknown option "-values"
The problem is located in the "update()" function
Code:
from pynput import *
import tkinter as tk
from tkinter import ttk
import time, threading
#
count = 0
Selected = "none"
options = ["action 1"]
class Action():
def __init__(self, assigned, action, cordX, cordY):
self.assigned = assigned
self.action = action
self.cordX = cordX
self.cordY = cordY
class Program(tk.Tk):
def __init__(self, title, minSize):
#Main Setup
super().__init__()
self.title (title)
self.geometry(f'{minSize[0]}x{minSize[1]}')
self.minsize(minSize[0],minSize[1])
#Widgets
self.menu = Menu(self)
#run
self.mainloop()
class Menu(ttk.Frame):
def __init__(self, parent):
super().__init__(parent)
self.place(x = 0, y = 0)
self.create_widgets()
def selected(event):
global selected
Textbox = Text(self, width=40, height=10)
Textbox.grid(row=1,column=0)
Selected = clicked.get()
print(Selected)
def ENTERINPUT():
global selected
f = open("Actions.txt", "a")
f.write(selected, assigned, action, cordX, cordY)
def create_widgets(self):
global options
clicked = tk.StringVar()
clicked.set(options[0])
ListOfActions = tk.OptionMenu(self, clicked, *options)
ListOfActions.grid(row = 0, column = 1, sticky = 'nsew', pady=20)
def update(): ## < THE PROBLEM
global options, count
count += 1
options.append("action" + str(count))
ListOfActions['values'] = options
print(options)
#create widgets
button1 = ttk.Button(self, text = "Add Action", command=update)
#create grid
self.columnconfigure((0,1,2), weight = 1, uniform = 'a')
self.rowconfigure((0,1,2,3,4), weight = 1, uniform = 'a')
#place widgets
button1.grid(row = 0, column = 0, sticky = 'nsew', pady=20)
Program("Automation Program", (300,250))
I've looked and found other users who used the same code but didn't have errors. Maybe it's a version thing?