jeudi 21 octobre 2021

Checkboxes not getting value when inside another function

I am new to python and stackoverflow so sorry if I did some mistakes. So I have a problem when making a mock Covid 19 app for my uni assignment. I'm using tkinter to make the GUI and the problem starts when ranking people if they are high risk or low risk based on the questions prepared. When I code in another file, it works fine, but when I put it in my full GUI, it wont get the value. This is the part where they work ;

def risk() :

    Q1 = x01.get() 
    Q2 = x02.get() 
    Q3 = x03.get() 
    Q4 = x04.get() 
    Q5 = x05.get()  
    Q6 = x06.get()  
    Q7 = x07.get() 
    Q8 = x08.get() 
    Q9 = x09.get()
    Q10 = x10.get()
    Q11 = x11.get()

    eg = [Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9 ,Q10, Q11]
    print(eg)


def update() :

    updatescreen = Tk()
    updatescreen.geometry('690x690')
    updatescreen.title('Update Covid-19 Status')
    updatescreen.config(background = '#735DA2')
    global x01
    global x02
    global x03
    global x04
    global x05
    global x06
    global x07
    global x08
    global x09
    global x10
    global x11

    x01 = IntVar()
    x02 = IntVar()
    x03 = IntVar()
    x04 = IntVar()
    x05 = IntVar()
    x06 = IntVar()
    x07 = IntVar()
    x08 = IntVar()
    x09 = IntVar()
    x10 = IntVar()
    x11 = IntVar()

    Label(updatescreen, text = 'Update Covid-19 Status', bg = '#965DA2', fg = 'white', width = 420, height = 2).pack()

    Label(updatescreen, text="", bg = '#735DA2').pack()

    Label(updatescreen, text="Have you returned from an overseas trip in the past 14 days?", bg = '#735DA2', fg = 'black').pack()
    Checkbutton(updatescreen, text = 'click if yes', variable = x01, onvalue = 1, offvalue = 0, bg = '#735DA2').pack()

    Label(updatescreen, text="Did you attend any gatherings identified as clusters by MOH in the past 14 days?", bg = '#735DA2', fg = 'black').pack()
    Checkbutton(updatescreen, text = 'click if yes', variable = x02, onvalue = 1, offvalue = 0, bg = '#735DA2').pack() 

    Label(updatescreen, text="Are you a close contact of a confirmed COVID-19 person?", bg = '#735DA2', fg = 'black').pack()
    Checkbutton(updatescreen, text = 'click if yes', variable = x03, onvalue = 1, offvalue = 0, bg = '#735DA2').pack()

    Label(updatescreen, text="Any of your family household members being confirmed positive for COVID-19?", bg = '#735DA2', fg = 'black').pack()
    Checkbutton(updatescreen, text = 'click if yes', variable = x04, onvalue = 1, offvalue = 0, bg = '#735DA2').pack()

    Label(updatescreen, text="Have you been working / face-to-face in the same confined space with less than 1-meter distance for more than 15 minutes?", bg = '#735DA2', fg = 'black').pack()
    Checkbutton(updatescreen, text = 'click if yes', variable = x05, onvalue = 1, offvalue = 0, bg = '#735DA2').pack()

    Label(updatescreen, text="Have you been in the same vehicle (more than 2 hours) within 2 meters from an individual who is positive of COVID-19?", bg = '#735DA2', fg = 'black').pack()
    Checkbutton(updatescreen, text = 'click if yes', variable = x06, onvalue = 1, offvalue = 0, bg = '#735DA2').pack()

    Label(updatescreen, text="", bg = '#735DA2').pack()

    Label(updatescreen, text = 'Symptoms', bg = '#965DA2', fg = 'white', width = 420, height = 2).pack()
    Label(updatescreen, text="", bg = '#735DA2').pack()

    Label(updatescreen, text="Fever?", bg = '#735DA2', fg = 'black').pack()
    Checkbutton(updatescreen, text = 'click if yes', variable = x07, onvalue = 1, offvalue = 0, bg = '#735DA2').pack()


    Label(updatescreen, text="Cough?", bg = '#735DA2', fg = 'black').pack()
    Checkbutton(updatescreen, text = 'click if yes', variable = x08, onvalue = 1, offvalue = 0, bg = '#735DA2').pack()

    Label(updatescreen, text="Sore Throat?", bg = '#735DA2', fg = 'black').pack()
    Checkbutton(updatescreen, text = 'click if yes', variable = x09, onvalue = 1, offvalue = 0, bg = '#735DA2').pack()

    Label(updatescreen, text="Runny Nose?", bg = '#735DA2', fg = 'black').pack()
    Checkbutton(updatescreen, text = 'click if yes', variable = x10, onvalue = 1, offvalue = 0, bg = '#735DA2').pack()


    Label(updatescreen, text="Shortness of Breath?", bg = '#735DA2', fg = 'black').pack()
    Checkbutton(updatescreen, text = 'click if yes', variable = x11, onvalue = 1, offvalue = 0, bg = '#735DA2').pack()

    Button(updatescreen, text = 'submit', width=10, height=2, bg='#5D69A2', fg='black', command = risk).pack()


    updatescreen.mainloop()

update()

The problem is when I put the in another function like so ;

def userprofile():
    global profilescreen
    profilescreen = Tk()
    profilescreen.geometry('420x420')
    profilescreen.title('User Profile')
    profilescreen.config(background = '#735DA2')

    Label(profilescreen, text = 'User Profile', bg = '#965DA2', fg = 'white', width = 420, height = 2).pack()

    Label(profilescreen, text="", bg = '#735DA2').pack()
    Label(profilescreen, text="", bg = '#735DA2').pack()
    Label(profilescreen, text="", bg = '#735DA2').pack()

    Button(profilescreen, text = 'Update Covid-19 Status', command = update, width=35, height=2, bg='#5D69A2', fg='black').pack()

    Label(profilescreen, text="", bg = '#735DA2').pack()

    Button(profilescreen, text = 'Check Appointment Date,Location, and Time', width=35, height=2, bg='#5D69A2', fg='black').pack()

    Label(profilescreen, text="", bg = '#735DA2').pack()

    Button(profilescreen, text = 'Respond to the Assigned Appointment', width=35, height=2, bg='#5D69A2', fg='black').pack()

    Label(profilescreen, text="", bg = '#735DA2').pack()

    profilescreen.mainloop()

    



def risk() :

    Q1 = x01.get() 
    Q2 = x02.get() 
    Q3 = x03.get() 
    Q4 = x04.get() 
    Q5 = x05.get()  
    Q6 = x06.get()  
    Q7 = x07.get() 
    Q8 = x08.get() 
    Q9 = x09.get()
    Q10 = x10.get()
    Q11 = x11.get()

    eg = [Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9 ,Q10, Q11]
    print(eg)


def update() :

    profilescreen.withdraw()
    global updatescreen
    updatescreen = Tk()
    updatescreen.geometry('690x690')
    updatescreen.title('Update Covid-19 Status')
    updatescreen.config(background = '#735DA2')

    global x01
    global x02
    global x03
    global x04
    global x05
    global x06
    global x07
    global x08
    global x09
    global x10
    global x11

    
    Label(updatescreen, text = 'Update Covid-19 Status', bg = '#965DA2', fg = 'white', width = 420, height = 2).pack()

    Label(updatescreen, text="", bg = '#735DA2').pack()

    x01 = IntVar()
    Label(updatescreen, text="Have you returned from an overseas trip in the past 14 days?", bg = '#735DA2', fg = 'black').pack()
    Checkbutton(updatescreen, text = 'click if yes', variable = x01, onvalue = 1, offvalue = 0, bg = '#735DA2').pack()

    x02 = IntVar()
    Label(updatescreen, text="Did you attend any gatherings identified as clusters by MOH in the past 14 days?", bg = '#735DA2', fg = 'black').pack()
    Checkbutton(updatescreen, text = 'click if yes', variable = x02, onvalue = 1, offvalue = 0, bg = '#735DA2').pack() 

    x03 = IntVar()
    Label(updatescreen, text="Are you a close contact of a confirmed COVID-19 person?", bg = '#735DA2', fg = 'black').pack()
    Checkbutton(updatescreen, text = 'click if yes', variable = x03, onvalue = 1, offvalue = 0, bg = '#735DA2').pack()

    x04 = IntVar()
    Label(updatescreen, text="Any of your family household members being confirmed positive for COVID-19?", bg = '#735DA2', fg = 'black').pack()
    Checkbutton(updatescreen, text = 'click if yes', variable = x04, onvalue = 1, offvalue = 0, bg = '#735DA2').pack()

    x05 = IntVar()
    Label(updatescreen, text="Have you been working / face-to-face in the same confined space with less than 1-meter distance for more than 15 minutes?", bg = '#735DA2', fg = 'black').pack()
    Checkbutton(updatescreen, text = 'click if yes', variable = x05, onvalue = 1, offvalue = 0, bg = '#735DA2').pack()

    x06 = IntVar()
    Label(updatescreen, text="Have you been in the same vehicle (more than 2 hours) within 2 meters from an individual who is positive of COVID-19?", bg = '#735DA2', fg = 'black').pack()
    Checkbutton(updatescreen, text = 'click if yes', variable = x06, onvalue = 1, offvalue = 0, bg = '#735DA2').pack()

    Label(updatescreen, text="", bg = '#735DA2').pack()

    Label(updatescreen, text = 'Symptoms', bg = '#965DA2', fg = 'white', width = 420, height = 2).pack()
    Label(updatescreen, text="", bg = '#735DA2').pack()

    x07 = IntVar()
    Label(updatescreen, text="Fever?", bg = '#735DA2', fg = 'black').pack()
    Checkbutton(updatescreen, text = 'click if yes', variable = x07, onvalue = 1, offvalue = 0, bg = '#735DA2').pack()

    x08 = IntVar()
    Label(updatescreen, text="Cough?", bg = '#735DA2', fg = 'black').pack()
    Checkbutton(updatescreen, text = 'click if yes', variable = x08, onvalue = 1, offvalue = 0, bg = '#735DA2').pack()

    x09 = IntVar()
    Label(updatescreen, text="Sore Throat?", bg = '#735DA2', fg = 'black').pack()
    Checkbutton(updatescreen, text = 'click if yes', variable = x09, onvalue = 1, offvalue = 0, bg = '#735DA2').pack()

    x10 = IntVar()
    Label(updatescreen, text="Runny Nose?", bg = '#735DA2', fg = 'black').pack()
    Checkbutton(updatescreen, text = 'click if yes', variable = x10, onvalue = 1, offvalue = 0, bg = '#735DA2').pack()

    x11 = IntVar()
    Label(updatescreen, text="Shortness of Breath?", bg = '#735DA2', fg = 'black').pack()
    Checkbutton(updatescreen, text = 'click if yes', variable = x11, onvalue = 1, offvalue = 0, bg = '#735DA2').pack()


    Button(updatescreen, text = 'submit', width=10, height=2, bg='#5D69A2', fg='black', command = risk).pack()


    updatescreen.mainloop()

userprofile()

Any kind of help would be very appreciated. This had me working on this part for hours. Thank you :)




Aucun commentaire:

Enregistrer un commentaire