I have a program called main.py:
def prog2():
exec(open("prog2.py").read())
buttonHMI = tk.Button(text="Program HMI", width=15, font=("Arial", 14), command=prog2)
buttonHMI.grid(column=0, row=3, columnspan=1, padx=20, pady=10, sticky=W)
So there's 1 button and when pressed it executes a 2nd program called prog2:
from tkinter import *
from tkinter import ttk
window = tk.Tk()
def close():
window.destroy
CB1 = Checkbutton(window, text="Enable VNC", font=("Arial", 12), variable=action_VNC)
CB1.grid(row=0, sticky=W, padx=10)
CB1.configure(bg='#34aeeb')
ButtonClose= tk.Button(window, text="Close", width=20, font=("Arial", 14), command=window.destroy)
ButtonClose.grid(columnspan=2, column = 3, row=9, sticky=W, padx=10, pady=10)
class Timer:
def __init__(self, window=None):
self.sv = tk.StringVar()
ButtonShow = tk.Button(window, text="Program HMI", width=20, font=("Arial", 14), command=self.actions)
ButtonShow.grid(columnspan=2, row=9, column = 0, sticky=W, padx=10, pady=10)
progress = ttk.Progressbar(window, orient = HORIZONTAL, length = 500, mode = 'determinate')
progress.grid(row=10, columnspan = 4, sticky=W, padx=10, pady=10)
outText = Text(window, width=50, height=20, wrap=WORD)
outText.grid(row=11, columnspan=4, padx=10)
###########################################################
#start actions.
def actions(self):
print("action")
Timer()
window.mainloop()
The problem I'm having is from main.py, I open prog2, some of the objects (Buttonshow, progress, outText) will show up in the main.py window. But CB1 and Close objects will show in prog2. If I execute prog2.py by itself, then all the objects will show correctly in prog2 window. How do I get all of prog2 objects to show in prog2?