Python Forum
How to get the value of a checkbox
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get the value of a checkbox
#1
I have a checkbutton in my program but when I click the checkbox, it gives me the following error: TypeError: get() missing 1 required positional argument: 'self' Below is the code along with the related function.


def getreservation():
    global arrivaldtee
    global my_box
    global conf
    global laste
    global firste
    global addresse
    global citye
    global statee
    global zipe
    global phonee
    global emaile
    global arrivale
    global departe
    global dayse
    global adultse
    global childrene
    global roomnum
    global ratee
    global taxe
    global dailye
    global staye
    global rateplancombo
    global paymente
    global rateplane
    global checksmoke
    global checkpet
    global notese
    global ide
    global confnume
    global var3
    global var10
    global var13





    greserve = Toplevel()
    greserve.title('Retrieve Reservations')
    greserve.state('zoomed')
    #greserve.geometry("1400x800+250+50")
    greserve.configure(bg='#AFEEEE')

    now = dt.datetime.now()
    newdate = now + timedelta(days=1)
    diff = newdate - now
    diff2 = str(diff)


    labelintro = Label(greserve, text="Retrieve Reservation", bg="#AFEEEE")
    labelintro.config(font=("Times New Roman", 16))
    labelintro.place(x=10, y=0)

    last = Label(greserve, text="Last", bg="#AFEEEE")
    last.place(x=35, y=30)
    laste = Entry(greserve, width=30)
    laste.place(x=70, y=30)

    first = Label(greserve, text="First", bg="#AFEEEE")
    first.place(x=35, y=50)
    firste = Entry(greserve, width=30)
    firste.place(x=70, y=50)

    address = Label(greserve, text="Address", bg="#AFEEEE")
    address.place(x=16, y=70)
    addresse = Entry(greserve, width=50)
    addresse.place(x=70, y=70)

    city = Label(greserve, text="City", bg="#AFEEEE")
    city.place(x=35, y=90)
    citye = Entry(greserve, width=40)
    citye.place(x=70, y=90)

    state = Label(greserve, text="State", bg="#AFEEEE")
    state.place(x=320, y=90)
    statee = Entry(greserve, width=20)
    statee.place(x=355, y=90)

    zip = Label(greserve, text="Zip Code", bg="#AFEEEE")
    zip.place(x=15, y=110)
    zipe = Entry(greserve, width=10)
    zipe.place(x=70, y=110)

    phone = Label(greserve, text="Phone", bg="#AFEEEE")
    phone.place(x=27, y=130)
    phonee = Entry(greserve, width=20)
    phonee.place(x=70, y=130)

    email = Label(greserve, text="Email", bg="#AFEEEE")
    email.place(x=27, y=150)
    emaile = Entry(greserve, width=50)
    emaile.place(x=70, y=150)

    line = Label(greserve, text="=======================================================", bg="#AFEEEE")
    line.place(x=0, y=170)

    arrival = Label(greserve, text="Arrival Date", bg="#AFEEEE")
    arrival.place(x=33, y=190)
    arrivale = Entry(greserve, width=20)
    arrivale.place(x=110, y=190)
    arrivale.bind("<Button-1>", aexample1)
    # dayss = now.strftime("%m-%d-%Y") + 1

    depart = Label(greserve, text="Departure Date", bg="#AFEEEE")
    depart.place(x=15, y=210)
    departe = Entry(greserve, width=20)
    departe.place(x=110, y=210)
    departe.bind("<Button-1>", example1)

    days = Label(greserve, text="Days", bg="#AFEEEE")
    days.place(x=70, y=230)
    rvar11 = DoubleVar()
    dayse = Entry(greserve, textvariable=rvar11, width=20)
    dayse.delete(0, END)
    dayse.place(x=110, y=230)

    adults = Label(greserve, text="Adults", bg="#AFEEEE")
    adults.place(x=62, y=250)
    adultse = Entry(greserve, width=20)
    adultse.place(x=110, y=250)

    children = Label(greserve, text="Children", bg="#AFEEEE")
    children.place(x=54, y=270)
    childrene = Entry(greserve, width=20)
    childrene.place(x=110, y=270)



    options = [
        "Select Room",
    ]
    conn = sqlite3.connect('roominventory.db')
    c = conn.cursor()
    c.execute("SELECT * FROM rooms")
    records = c.fetchall()

    for record in records:
        if record[3] != "N":
            addie = record[0:2]
            options.append(addie)

    room = Label(greserve, text="Room", bg="#AFEEEE")
    room.place(x=67, y=290)
    roomnum = Entry(greserve, width=20)
    roomnum.place(x=110, y=290)

    checkincombbo = ttk.Combobox(greserve, width=17, value=options)
    checkincombbo.place(x=245, y=290)
    checkincombbo.current(0)
    checkincombbo.bind("<<ComboboxSelected>>", comboroom)

    ratel = Label(greserve, text="Rate", bg="#AFEEEE")
    ratel.place(x=75, y=310)
    ratee = Entry(greserve, width=20)
    ratee.place(x=110, y=310)
    ratee.bind("<Return>", changerate)

    tax = Label(greserve, text="Tax", bg="#AFEEEE")
    tax.place(x=80, y=330)
    taxe = Entry(greserve, width=20)
    taxe.place(x=110, y=330)

    var13 = IntVar()
    checktax = Checkbutton(greserve, bg="#AFEEEE", onvalue=1, command=rtaxselect, variable=var13)
    checktax.place(x=55, y=330)
    checktax.select()

    daily = Label(greserve, text="Daily Amount", bg="#AFEEEE")
    daily.place(x=27, y=350)
    dailye = Entry(greserve, width=20)
    dailye.place(x=110, y=350)

    stay = Label(greserve, text="Stay Amount", bg="#AFEEEE")
    stay.place(x=30, y=370)
    staye = Entry(greserve, width=20)
    staye.place(x=110, y=370)

    options2 = [
        "Select Rate Plan",
        "RACK",
        "AAA",
        "Senior",
        "Government",
        "Trucker",
        "---",
        "---",
        "---",

    ]

    rateplan = Label(greserve, text="Rate Plan", bg="#AFEEEE")
    rateplan.place(x=50, y=390)
    rateplane=Entry(greserve, width=20)
    rateplane.place(x=110, y=390)

    rateplancombo = ttk.Combobox(greserve, width=17, value=options2)
    rateplancombo.place(x=245, y=390)
    rateplancombo.current(0)
    rateplancombo.bind("<<ComboboxSelected>>", rateplan)

    payment = Label(greserve, text="Payment", bg="#AFEEEE")
    payment.place(x=50, y=410)
    paymente = Entry(greserve, width=20)
    paymente.place(x=110, y=410)

    var10 = IntVar()
    checksmoke = Checkbutton(greserve, text="Smoker", bg="#AFEEEE", onvalue=1, offvalue=0, variable=var10,
                             command=selectsmoke)
    checksmoke.place(x=105, y=440)

    var3 = IntVar()
    checkpet = Checkbutton(greserve, text="Pet", bg="#AFEEEE", command=petbox, variable=var3)
    checkpet.place(x=105, y=470)

    line2 = Label(greserve, text="=======================================================", bg="#AFEEEE")
    line2.place(x=0, y=490)

    my_box = Listbox(greserve, height=19, width=125)
    my_box.place(x=600, y=180)
    my_box.bind("<<ListboxSelect>>", checkinreservation)



    options5 = [
        "Select Payment",
        "Visa",
        "Master Card",
        "Discover",
        "American Exp.",
        "Diners",
        "Cash",
        "Travelers Check",
        "Personal Check"

    ]

    paymentcombo = ttk.Combobox(greserve, width=17, value=options5)
    paymentcombo.place(x=245, y=410)
    paymentcombo.current(0)
    # paymentcombo.bind("<<ComboboxSelected>>", payselect)

    notes = Label(greserve, text="NOTES:", bg="#AFEEEE")
    notes.place(x=10, y=520)
    notese = Entry(greserve, width=73)
    notese.place(x=10, y=540)

    id = Label(greserve, text="ID", bg="#AFEEEE")
    id.place(x=40, y=565)
    ide=Entry(greserve, width=10)
    ide.place(x=60, y=565)

    confnum=Label(greserve, text="Conf. #", bg="#AFEEEE")
    confnum.place(x=10, y=585)
    confnume = Entry(greserve, width=10)
    confnume.place(x=60, y=585)

    checkin = Button(greserve, text="Check In", command=checkinreserve)
    checkin.place(x=1300, y=500)


    update = Button(greserve, text="Update Reservation", command=updatereserve)
    update.place(x=1150, y=500)

    ext = Button(greserve, text="Exit-->", command=greserve.destroy)
    ext.place(x=1090, y=500)

    arrivaldte = Label(greserve, text="Arrival Date", bg="#AFEEEE")
    arrivaldte.place(x=600, y=160)

    arrivaldtee =Entry(greserve, width=20)
    arrivaldtee.place(x=675, y=160)
    arrivaldtee.bind("<Button-1>", rexample1)

    search=Button(greserve, text="Search....", command=searcharrival)
    search.place(x=800, y=155)

    searchall = Button(greserve, text="Search All", command=searchallres)
    searchall.place(x=875, y=155)

    searchconf = Label(greserve, text="Confirmation#", bg="#AFEEEE")
    searchconf.place(x=980, y=160)

    conf = Entry(greserve, width=20)
    conf.place(x=1070, y= 160)

    confbtn = Button(greserve, text="Go...", command=searchconfn)
    confbtn.place(x=1200, y=155)

def rtaxselect():

    print(var13)
    if var13.get() == 0:
        taxe.delete(0, END)
Reply
#2
(May-14-2020, 02:07 PM)scratchmyhead Wrote: I have a checkbutton in my program but when I click the checkbox, it gives me the following error: TypeError: get() missing 1 required positional argument: 'self' Below is the code along with the related function.


def rtaxselect(self):

should it be
Reply
#3
That didn't work. Sorry.
Reply
#4
(May-14-2020, 02:24 PM)scratchmyhead Wrote: That didn't work. Sorry.

then please post the entire code, so I / any other person can reconstructure the issue.
Reply
#5
Ok, I figured it out. I changed from TopLevel() to Tk() Why that makes a difference I don't know but it worked.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] choose checkbox devilonline 1 1,282 Feb-17-2023, 01:23 PM
Last Post: Axel_Erfurt
  [Tkinter] Dynamic checkbox treeview issue OogieM 8 4,909 Mar-20-2022, 02:10 PM
Last Post: OogieM
  tkinter change the text of the checkbox zazas321 1 3,829 Sep-17-2021, 06:19 AM
Last Post: zazas321
  Tkinter checkbox value scratchmyhead 5 3,682 May-09-2020, 11:44 PM
Last Post: menator01
  TreeviewWith CheckBox issac_n 1 7,741 Mar-08-2020, 06:51 AM
Last Post: shamnadinn
  Tkinter Checkbox niro_one 1 2,344 Jan-13-2020, 11:31 AM
Last Post: joe_momma
  [Tkinter] Unable to create checkbox and select at run time tej7gandhi 5 4,655 May-05-2019, 04:57 PM
Last Post: tej7gandhi
  [PyQt] PyQt4 handle dynamic checkbox click littleGreenDude 1 6,581 Dec-27-2018, 09:17 PM
Last Post: littleGreenDude
  [Tkinter] Completing Action when CheckBox is Checked Anysja 2 7,966 Aug-02-2018, 04:38 PM
Last Post: Anysja
  Displaying error in QTableview and with Checkbox in Column under macOsX nieselfriem 1 5,435 Mar-19-2017, 10:43 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020