Hey guys,

I am having some trouble getting my head around tkinter at the moment. I am new to programming and have been using python for about 2 months now.

The problem I am having is with RadioButtons. I have a set of radio buttons numbered 1-9 and I can select any number with a mouse left click(this part works fine) and I want to be able to click on my grid canvas(9 rows 9 columns) I have made and place the selected RadioButton number in the grid.

My main question I spose is.. do I have to make an event for every time I click in a different box(x,y position) in my grid? Or do I tag the create.line code that I made the grid with?

BTW I made the grid in the slow newbie way with create line over and over again :S don't know if this makes any difference to the tagging of the x,y co ords.

Sorry if this doesn't make to much sense..trying to get my head around this all day.

Thanks for any help you can give me.

Here is a typical example of multiple radiobuttons using the Tkinter GUI toolkit:

# exploring multiple Tkinter radio buttons
# radio buttons only allow one item to be selected/checked
# ene

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

def rb_selected():
    # show checked/selected radio button item
    ix = rb_v.get()
    label['text'] = 'you selected %s' % mylist[ix]

root = tk.Tk()

# used by the radio buttons as index
rb_v  = tk.IntVar()

mylist = [
'apple',
'orange',
'banana',
'pear',
'apricot'
]

# list(range()) needed for Python3
rb = list(range(len(mylist)))
for ix, text in enumerate(mylist):
    # command is optional and responds to any rb changes
    rb[ix] = tk.Radiobutton(root, text=text, value=ix,
        variable=rb_v, command=rb_selected)
    rb[ix].grid(row=ix, column=0, sticky='w')

label = tk.Label(root, width=20)
label.grid(row=ix+1, column=0, pady=5, sticky='w')

# you can preset one radio button
# default is first button (ix=0)
rb_v.set(2)
# show initial selection
rb_selected()

root.mainloop()

I am sure you can adapt it to your purposes easily. Just play around with the code a little.

Thanks for all of your code Ene Uran.
It got me on the right path. I found out I don't need to go into as much detail.
I just got the coord with a Button-1 click event and run some other functions through it to convert the xy coord into row column values.
Thanks again :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.