0

I'm currently trying to create a quiz in python using tkinter. I'd like to use the RadioButtons as multiple choices, but I don't really know how to connect the selected choice with the CommandButton. I found a similar program to the one I'm trying to create, but still I don't understand it. Could someone please help me?

I fail to understand why in the function is called call(par) and the command is command =lambda: call(correct.get())

    import Tkinter as tk
    root = tk.Tk()

    def call(par):
        if par:
            lab2 = tk.Label(root, text='CORECT!!!!').grid(row=4)
        else:
            lab2 = tk.Label(root, text='of corse your wrong').grid(row=4)
            lab2 = tk.Label(root, text='how could you be so stupid?').grid(row=5)

    correct  = tk.BooleanVar()
    rad = tk.Radiobutton(root, text='yes', variable=correct, value=True)
    rad2 = tk.Radiobutton(root, text='no', variable=correct, value=False)
    lab = tk.Label(root, text='Is the maker awsome?')
    btn = tk.Button(root, text='submit', command=lambda: call(correct.get()))

    lab.grid(row=0)
    rad.grid(row=2, column=0)
    rad2.grid(row=2, column=1)
    btn.grid(row=3)

    tk.mainloop()  
Artemis
  • 2,553
  • 7
  • 21
  • 36
  • 1
    Could you be more specific about what you do and don't understand? Have a read of e.g. http://stackoverflow.com/q/8269096/3001761 and the linked questions. – jonrsharpe Nov 05 '16 at 20:42
  • The command is `command=lambda: call(correct.get())` and not just `command=call` because a button command is a function that takes no argument while the `call` function takes one. So the `lambda` syntax is used to pass the argument to `call`. – j_4321 Nov 06 '16 at 13:58
  • Thank you very much! The linked questions already helped me a lot, everything is clear now – Emma Ceccaroni Nov 14 '16 at 17:55

0 Answers0