jeudi 4 juillet 2019

Function does not print the right output

I have written a small app with checkboxes, so when i mark one or both of them it should print a specific variable, though, the problem lays here, when i mark both of the checkboxes, i don't get the output i want. Thank You

from tkinter import *
class STproject():

    def __init__(self,app):

        self.CheckVar1 =IntVar()
        self.CheckVar2 =IntVar()

        self.button=Button(app,text='PRINT',command=lambda:self.functionality())
        self.button.grid(row=0,column=0)
        self.Lidbox=Checkbutton(app,variable=self.CheckVar1,onvalue=1,
                           offvalue=0)
        self.Lidbox.grid(row=1,column=0)
        self.Seperatorbox=Checkbutton(app,variable=self.CheckVar2,onvalue=1,
                           offvalue=0)
        self.Seperatorbox.grid(row=1,column=1)

    def functionality(self):
        if self.CheckVar1.get():
            print('first')
        elif self.CheckVar2.get():
            print('2nd part')
        elif self.CheckVar1.get() and self.CheckVar2.get():
            print('3rd part')
        else:
            print('4th part')

root=Tk()
root.title('SteelBox Inc. Calculator')
application=STproject(root) #2
root.mainloop() #3

Aucun commentaire:

Enregistrer un commentaire