Q: Tk Window closing not going to classes I've been running my code on python idle while working on this and didn't receive any problems until I tried running it on visual studio. When running it the tk window just closes and it doesn't go to the classes it tells it too. I am still learning so I probably have some mistakes I would love to get any feedback.
import tkinter as tk
#Takes photos with certain char and if clicked another char program stops
from cv2 import *
import numpy as np
import cv2
import os
from datetime import datetime


now = datetime.now()

time = now.strftime("%H:%M:%S")

#sets the directory and text info
os.chdir(r"C:\Users\asdasd\Desktop\camera")
file_name = 'pic'
cam = cv2.VideoCapture(0)
font = cv2.FONT_HERSHEY_TRIPLEX
org = (00,300)
fontScale = 1
color = (255,0,0)
thickness = 1

root= tk.Tk()

photo = tk.PhotoImage(file=r"C:\Users\asdas\Desktop\camera\pic.png")
root.iconphoto(False, photo)
root.geometry("+0+50")

print("created window")
#Creates window
canvas1 = tk.Canvas(root, width = 600, height = 600)
canvas1.pack()
canvas1.configure(bg='lightgray')
root.title("ShippingData")
root.lift()
#text label for batch #
label1 = tk.Label(root, text='Enter Batch# :')
label1.config(font=('helvetica', 15))
canvas1.create_window(65, 50, window=label1)

print("created window")
#creates input window for batch #
entry1 = tk.Entry (root)
canvas1.create_window(200, 50, window=entry1)

#text label for initials
label1 = tk.Label(root, text='Enter initials :')
label1.config(font=('helvetica', 15))
canvas1.create_window(65, 100, window=label1)

#creates input window for intials
entry2 = tk.Entry (root)
canvas1.create_window(200, 100, window=entry2)

#gets the info after start button is pressed
def getInfo ():  
    print("getinfo")
    x1 = entry1.get()
    x2 = entry2.get()
    name = str(x1 + x2)
    global dirname
    dirname = name
    os.mkdir(dirname)

    label1 = tk.Label(root, text= "Program Starting")
    canvas1.create_window(200, 230, window=label1)
    canvas1.destroy()
    programStarted()

print("button")
button1 = tk.Button(root, text='Start', command=getInfo)
print("button created")
canvas1.create_window(200, 180, window=button1)
print("canvas created for window")

def programStarted():
    print("programstart")

    root.update()
    #creates new window
    global canvas2
    canvas2 = tk.Canvas(root, width = 400, height = 300)
    canvas2.pack()
    # Camera instructions
    label2 = tk.Label(root, text= "Press z to take Photos.")
    canvas2.create_window(200, 100, window=label2)  
    label3 = tk.Label(root, text= "Press c multiple times when finished to stop taking photos. ")
    canvas2.create_window(200, 150, window=label3)
    root.update()
    camera()


#camera program
def camera():
    print("camera")
    global n
    global time
    global path
    n= 1
    while(True):
        numphoto = "#" + str(n)
        ret, frame = cam.read()
        cv2.namedWindow("Shipping camera", cv2.WINDOW_NORMAL)
        scale_percent = 100 # percent of original size
        width = int(frame.shape[1] * scale_percent / 100)
        height = int(frame.shape[0] * scale_percent / 100)
        dim = (width, height)
        frame = cv2.resize(frame, dim, interpolation = cv2.INTER_AREA)
        scale_percent = 100 # percent of original size
        width = int(frame.shape[1] * scale_percent / 100)
        height = int(frame.shape[0] * scale_percent / 100)
        dim = (width, height)
        frame = cv2.resize(frame, dim, interpolation = cv2.INTER_AREA)
        cv2.putText(frame, numphoto, org, font, fontScale,color,thickness, cv2.LINE_AA, False)
        cv2.imshow('Shipping camera', frame)
        cv2.setWindowProperty("Shipping camera", cv2.WND_PROP_TOPMOST, 1)
        if cv2.waitKey(1) & 0xFF == ord('z'):
            n+=1
            cv2.imwrite(os.path.join(dirname,(file_name + (str(n-1)) + ".jpg")), frame)
            path = (os.path.join(str(r"C:\Users\sadsads\Desktop\camera"), str(dirname)))
        elif (cv2.waitKey(1) & 0xFF == ord('c')):
            # stops everything
            cam.release()
            cv2.destroyAllWindows()
            with open((path+r'\timelog.txt'), 'w') as f:
                f.write(time+ '\n')
                now = datetime.now()
                time2 = now.strftime("%H:%M:%S")
                f.write(time2+ '\n')
               
               
               
            y = 0
            if(y == 0):
                # destory the other windows
                root.quit()
                root.destroy()
                break  
            else:
                root.mainloop()

