Problem w/ Tkinter

Matt McCredie mccredie at gmail.com
Fri Aug 24 19:01:59 EDT 2007


On 8/24/07, Lamonte Harris <pyth0nc0d3r at gmail.com> wrote:
> How to fix my code, wth that doesn't help solve anything really.the Tkinter
> tutorial doesn't even explain radio buttons correctly, let alone, everything
> else. gah. can you give a answer that I can work from.

You asked, "what can I do to fix this problem?". You stated this in
the singular, implying that there was one problem with your code to
fix. In reality, to fix your code you have to totally re-write it. You
need to slowly work your way through tutorials and go through all the
pain everyone else who has learned Python and Tkinter has had to go
through if you want to be a compitent coder. I know these may seem
like harsh words, so let me give you an example of working Radiobutton
code.

[code]
import Tkinter as tk

choices = {1:"One", 2:"Two", 3:"Three", 4:"Four"}
def main():
    root = tk.Tk()

    global v
    v = tk.IntVar()

    for i, name in choices.iteritems():
        b = tk.Radiobutton(root, text=name, variable=v, value=i)
        b.pack(anchor='w')

    tk.Button(root, text="Action?", command=print_val).pack(anchor='w')

    root.mainloop()

def print_val():
    k = v.get()
    print k, choices[k]

if __name__ == "__main__":
    main()

[/code]

I'm curious, what do you feel is incorrect about the Radiobutton
explanation? It seemed to work for me.

Matt



More information about the Python-list mailing list