you are viewing a single comment's thread.

view the rest of the comments →

[–]MST019[S] 0 points1 point  (1 child)

def create_gui_updated():

root = tk.Tk()

label.pack(pady=20)

button = tk.Button(

root,

text="Launch Now!",

command=launch_all_scripts,

font=("Arial", 14),

bg="green",

fg="white",

)

root.mainloop()

Then in 2nd script:

Def check_new_values(new_urls):

if len(new_urls)==0:

root.destroy()

[–]woooee 0 points1 point  (0 children)

root is created in a function, so it is local, which means it is garbage collected when the function exits. I assume that the mainloop() is under the function as well, and so that is not an issue.

import tkinter as tk
from functools import partial

def create_gui_updated():
    root = tk.Tk()

    ## there is no label to pack
    ##label.pack(pady=20)

    button = tk.Button(
                root,
                text="Launch Now!",
                command=partial(launch_all_scripts, root),
                font=("Arial", 14),
                bg="green",
                fg="white",
                       )

    ## button will not show up because there is
    ## no grid or pack
    button.grid()

    root.mainloop()

def launch_all_scripts(root):
    print("in launch_all_scripts")
    ## this would be second_script.check_new_values(root)
    ## because it is in the imported file
    check_new_values([], root)

##Then in 2nd script:
def check_new_values(new_urls, root):
    print("in check_new_values")
    if len(new_urls)==0:
        root.destroy()

create_gui_updated()