samedi 17 avril 2021

I'm trying to get a value from a checkbox using .get() but the value doesn't seem to change

def AddNewFile():
    global Date
    global DateCreated
    global DateModified
    global Action
    global Project
    global Author
    global ReportNo
    global Vessel
    global Tag
    global Comments
    global Priorty
    global Completion
    global total_rows
    global InputProject
    global InputTag
    global vess
    global Com
    global InputPrioity
    global Completion
    path=Path.get()
    extracted_data=extract_information(path+'.pdf')
    print(extracted_data)
    if '/CreationDate' in extracted_data:
        use=str(extracted_data['/CreationDate'])
        creationdate=datetime.strptime(use[2:10],"%Y%m%d")
        DateCreated.append(str(creationdate)[0:10])
    if '/ModDate' in extracted_data:
        use=str(extracted_data['/ModDate'])
        moddate=datetime.strptime(use[2:10],"%Y%m%d")
        DateModified.append(str(moddate)[0:10])
    if '/Author' in extracted_data:
        Author.append(extracted_data['/Author'])
    if '/Subject' in extracted_data:
        ReportNo.append(extracted_data['/Subject'])
    today=datetime.today()
    print(Prio)  #I think this is where the problem is
    if Prio==1:
        Priority.append(str(Prio))
    else:
        Priority.append('0')
    Date.append(str(today)[0:10])
    Action.append(CalculateActionRequired(str(today)[0:10],len(Priority)-1))
    Project.append(InputProject.get())
    Tag.append(InputTag.get())
    Completion.append(0)
    Comments.append(comments_split(Com.get()))
    Vessel.append(vess.get())
    total_rows = len(Date)+1
    t=Table(root)
    AddNewFileToFile(Com.get())
    closewindow(AddFileWindow)

#This was my attempt of trying to fix the problem myself using another variable
def add_value_to_Priority():
    global Prio
    global InputPriority
    """if Prio==1: #This part was one attempt
        Prio=0
    else:
        Prio==1"""
    print(InputPriority.get())
    Prio=int(InputPriority.get())#This was another attempt

# this is the function called when the button is clicked, and calls the other subroutines above
def AddFileCmmd():
    global Prio
    global AddFileWindow
    global Path
    global InputPriority
    global InputProject
    global InputTag
    global vess
    global Com
    Prio=0
    AddFileWindow=Tk()
    AddFileWindow.title('Add file')
    AddFileWindow.geometry('500x500')
    Label(AddFileWindow,text='Enter File Name').grid()
    Path=Entry(AddFileWindow)
    Path.grid(sticky=E)
    InputProject=StringVar(AddFileWindow)
    InputProject.set('Input Project')
    w = OptionMenu(AddFileWindow, InputProject, "one", "two", "three")
    w.grid()
    InputTag=StringVar(AddFileWindow)
    InputTag.set('Input Tag')
    z = OptionMenu(AddFileWindow, InputTag, "one", "two", "three")
    z.grid()
    Label(AddFileWindow,text='Enter Vessel').grid()
    vess=Entry(AddFileWindow)
    vess.grid(sticky=E)
    Label(AddFileWindow,text='Enter Comments, seperate by |').grid()
    Com=Entry(AddFileWindow)
    Com.grid(sticky=E)
    InputPriority=IntVar()
# This is the checkbox which is not working
    Checkbutton(AddFileWindow, text='Prioity',variable=InputPriority, onvalue=1, offvalue=0,command=add_value_to_Priority).grid() 
    Button(AddFileWindow,text='Done',command=AddNewFile).grid() #This calls a procedure above
    AddFileWindow.mainloop()

Basically when the checkbox is clicked I assumed the value of InputPriority would change and I could use that to append to my array above so I could use it elsewhere. But when I click the checkbox it won't change. So I tried using another variable in a command triggered by the checkbox but this won't change either. I don't understand why it won't. Any help would be appreciated. (Sorry the code is a bit of a mess)




Aucun commentaire:

Enregistrer un commentaire