I'm trying to get my OptionMenu's to change once I make changes to the .txt file. I can restart the program and it be there but I don't want to have to restart if I make a change. I know I can change the optionmenu if the other optionmenu changes but I don't know how to do it if the outside file changes. https://www.dropbox.com/s/yvlqstof81o3t4z/Panels.txt?dl=0
import tkinter as tk
import re
root = tk.Tk()
panels = []
with open("Panels.txt") as panelfile:
for line in panelfile:
panellist = re.findall("'([^']*)'", line)
panels.extend(panellist)
wallpanelindex = panels.index('@Wall')
roofpanelindex = panels.index('@Roof')
wallpanellist = panels[(wallpanelindex+1):roofpanelindex] # Wall list
roofpanellist = panels[(roofpanelindex+1):] # Roof List
panel_type1 = wallpanellist[::3] # Wall Panel
panel_type2 = roofpanellist[::3] # Roof Panel
panel_width = roofpanellist[1::3] #Roof Panel Width
roofpaneldesc = roofpanellist[2::3] # Wall Panel Description
panel1 = tk.StringVar() # Wall Panel
panel1.set(panel_type1[1]) # Set Default
panel2 = tk.StringVar() # Roof Panel
panel2.set(panel_type2[1]) # Set Default
def panels():
from os import startfile
startfile(<<File Location>>Panels.txt)
def prnt():
print(panel_type2[panel_type2.index(panel2.get())], panel_width[panel_type2.index(panel2.get())], wallpaneldesc[panel_type2.index(panel2.get())])
mpanelwall = tk.OptionMenu(root, panel1, *panel_type1)
mpanelroof = tk.OptionMenu(root, panel2, *panel_type2)
mpanelwall.place(y=50)
mpanelroof.place(y=80)
btn3 = tk.Button(root, text="Panels", command=panels)
btn3.place(y=110) # Panel
btn10 = tk.Button(root, text="Print", command=prnt)
btn10.place(y=140) # Panel
root.mainloop()