-3

Excuse me, I wantenter image description here to ask, I have a problem trying to find out the number of checkboxes, I have repaired it for 2 days but it has failed, I really ask for guidance and help to fix it so that it can run normally, by the way I have only learned python for 1 week, thank you

this is my code:

def apa_bae():
    print("No.Rekam Medis: %d,\nNama Pasien: %d" % (var1.get(), var2.get()))
def alah():
    master = Tk()
    Label(master, text="Data Kuantitatif:").grid(row=0, sticky=W)
    var1 = IntVar()
    Checkbutton(master, text="No.Rekam medis", variable=var1).grid(row=1, sticky=W)
    var2 = IntVar()
    Checkbutton(master, text="Nama Pasien", variable=var2).grid(row=2, sticky=W)
    var3 = IntVar()
    Checkbutton(master, text="Tanggal Lahir", variable=var3).grid(row=3, sticky=W)
    var4 = IntVar()
    Checkbutton(master, text="Jenis Kelamin", variable=var4).grid(row=4, sticky=W)
    var5 = IntVar()
    Checkbutton(master, text="Kode Dokter", variable=var5).grid(row=5, sticky=W)
    var6 = IntVar()
    Checkbutton(master, text="Nama Dokter", variable=var6).grid(row=6, sticky=W)
    Button(master, text='Quit', command=master.quit).grid(row=7, sticky=W, pady=4)
    Button(master, text='Show', command=apa_bae).grid(row=8, sticky=W, pady=4)
    mainloop()
  • 1
    [Please do not upload images of code/errors when asking a question.](//meta.stackoverflow.com/q/285551) Include your code as a [formatted code block](//stackoverflow.com/help/formatting) instead of an image. – Pranav Hosangadi Nov 05 '20 at 16:38
  • 2
    What is `var1`? Where is it defined? Why do you suppose `apa_bae()` should have access to it? Read up about the scope of variables in Python. Does this answer your question? [Short description of the scoping rules?](https://stackoverflow.com/questions/291978/short-description-of-the-scoping-rules) – Pranav Hosangadi Nov 05 '20 at 16:40

1 Answers1

0

In apa_bae, you refer to var1 and var2. However, the only place those are defined is within the scope of the function alah; meaning outside of that function, those names won't be defined. In order to keep a reference to them outside of those two functions, you could use globals, class variables or you could pass them by reference.

Random Davis
  • 6,662
  • 4
  • 14
  • 24