Radiobutton Selection
<p>I am trying to make a game by combining Turtle and Tkinter. My code is working good but I have a problem with selection of <code>Radiobutton</code> part. When I try to select the "Black" (colored) radiobutton, I am not able to select it, however, there is no problem with other colors selection. Another problem is that I would like to use "No color" option and when the user selects it, shape must be drawn with no filling. But it does not work, it gets filled with a color selected automatically. I do not get how it is selected automatically. How can I fix that problem?</p>

<pre><code>import tkinter
from tkinter import *
import turtle
import sys
sc=Tk()
sc.geometry("1000x1000+100+100")

var= IntVar()
pensize=StringVar()
angle=StringVar()
radius=StringVar()
lenght=StringVar()

#FRAMES
fr1=Frame(sc,height=200,width=200,bd=4,bg="light green",takefocus="",relief=SUNKEN)
fr1.grid(row=0,column=0,sticky=(N,E,W,S))
 #FR2
fr2=Frame(sc,height=200,width=200,bd=4,bg="light green",takefocus="",relief=SUNKEN)
fr2.grid(row=1,column=0,sticky=(N,E,W,S))
 #FR3
fr3=Frame(sc,height=200,width=200,bd=4,bg="light green",takefocus="",relief=SUNKEN)
fr3.grid(row=2,column=0,sticky=(N,E,W,S))
 #FR4
fr4=Frame(sc,height=500,width=600,bd=4,bg="light green",takefocus="",relief=SUNKEN)
fr4.grid(row=2,column=2,sticky=(N,E,W,S))
 #FR5
fr5=Frame(sc,height=100,width=600,bd=4,bg="gray",takefocus="",relief=SUNKEN)
fr5.grid(row=1,column=2,sticky=(N,E,W,S))

#Canvas
canvas = Canvas(fr4,width=750, height=750)
canvas.pack()

#Turtle
turtle1=turtle.RawTurtle(canvas)
turtle1.color("blue")
turtle1.shape("turtle")

#Functions
def rectangle():
    turtle1.begin_fill()
    colorchoices()
    turtle1.pensize(int(pensize.get()))               
    for i in range(4):
        turtle1.forward(int(lenght.get()))
        turtle1.left(90)
    turtle1.end_fill()

def circle():
    turtle1.begin_fill()
    turtle1.pensize(int(pensize.get()))
    colorchoices()
    turtle1.circle(int(radius.get()))
    turtle1.end_fill()

def triangle():
    turtle1.begin_fill()
    colorchoices()
    turtle1.pensize(int(pensize.get()))
    turtle1.forward(int(lenght.get()))
    turtle1.left(120)
    turtle1.forward(int(lenght.get()))
    turtle1.left(120)
    turtle1.forward(int(lenght.get()))
    turtle1.end_fill()

def line100 ():
    turtle1.penup()
    turtle1.pensize(int(pensize.get()))
    turtle1.forward(int(lenght.get()))
    turtle1.pendown()

def linel90 ():
    turtle1.penup()
    turtle1.left(int(angle.get()))
    turtle1.pendown()

def liner90 ():
    turtle1.penup()
    turtle1.pensize(int(pensize.get()))
    turtle1.right(int(angle.get()))
    turtle1.pendown()

def linebc100 ():
    turtle1.penup()
    turtle1.begin_fill()
    colorchoices()
    turtle1.pensize(int(pensize.get()))
    turtle1.backward(int(lenght.get()))

    turtle1.end_fill()
    turtle1.pendown()

def line():

    turtle1.begin_fill()
    colorchoices()
    turtle1.pensize(int(pensize.get()))
    turtle1.forward(int(lenght.get()))
    turtle1.end_fill()

def colorchoices():
    selection=var.get()
    for i in range(7):
        if selection==1:
            turtle1.fillcolor("red")
        elif selection==2:
            turtle1.fillcolor("blue")
        elif selection==3:
            turtle1.fillcolor("purple")
        elif selection==4:
            turtle1.fillcolor("yellow")
        elif selection==5:
            turtle1.fillcolor("black")
        elif selection==6:
            turtle1.fillcolor("green")    
        else:
            return

def clear():
    turtle1.clear()




but1=Button(fr1,text="Clear",command=clear).pack(side=LEFT)
# shapes
shpc=PhotoImage(file="D://python//Ä±mage/circle.png")
shptr=PhotoImage(file="D://python//Ä±mage/rectangular.png")
shpsq=PhotoImage(file="D://python//Ä±mage/square.png")
shpl=PhotoImage(file="D://python//Ä±mage/line.png")
shphep=PhotoImage(file="D://python//Ä±mage/shapes.png")

#Entry and labels
PenSize=Button(fr5,text="PenSize",font=("Helvetica",14),fg="black").grid(row=0,column=0,columnspan=1,sticky=W)
Angle=Button(fr5,text="Angle",font=("Helvetica",14),fg="black").grid(row=1,column=0,columnspan=1,sticky=W)
Radius=Button(fr5,text="Radius",font=("Helvetica",14),fg="black").grid(row=2,column=0,columnspan=1,sticky=W)
Lenght=Button(fr5,text="Lenght",font=("Helvetica",14),fg="black").grid(row=3,column=0,columnspan=1,sticky=W)
pensize=Entry(fr5)
angle=Entry(fr5)
radius=Entry(fr5)
lenght=Entry(fr5)
pensize.grid(row=0,column=1,columnspan=2,sticky=W)
angle.grid(row=1,column=1,columnspan=2,sticky=W)
radius.grid(row=2,column=1,columnspan=2,sticky=W)
lenght.grid(row=3,column=1,columnspan=2,sticky=W)



#optionmenu
ColorOption=Button(fr5,text="ColorOptions",font=("Helvetica",14),fg="black").grid(row=4,column=0,sticky=W)
R1 = Radiobutton(fr5, text="RED", variable=var, value=1,bg="red").grid(row=4,column=1,sticky=W)
R2 = Radiobutton(fr5, text="BLUE", variable=var, value=2,bg="blue").grid( row=4,column=2,sticky=W)
R3 = Radiobutton(fr5, text="PURPLE", variable=var, value=3,bg="purple").grid( row=4,column=3,sticky=W )
R4 = Radiobutton(fr5, text="YELLOW", variable=var, value=4,bg="yellow").grid( row=4,column=4,sticky=W)
R5 = Radiobutton(fr5, text="BLACK", variable=var, value=5,bg="black",fg="white").grid( row=4,column=5,sticky=W )
R6 = Radiobutton(fr5, text="GREEN", variable=var, value=6,bg="green").grid( row=4,column=6,sticky=W)
R7 = Radiobutton(fr5, text="NO COLOR", variable=var, value=7).grid( row=4,column=7,sticky=W)

#Buttons
but1=Button(fr2,text="Forward",command=line100).grid(row=1,column=2,sticky=(N,E,W,S))
but1=Button(fr2,text="Backward",command=linebc100 ).grid(row=1,column=0,sticky=(N,E,W,S))
but1=Button(fr2,text="Turn90",command=linel90).grid(row=0,column=1,sticky=(N,E,W,S))
but1=Button(fr2,text="Turn(-90)",command=liner90).grid(row=2,column=1,sticky=(N,E,W,S))
#shp1=Label(fr5,text="SHAPES",image=shphep).pack(fill=X)
shp2=Button(fr3,text="Circle",height=200,width=200,image=shpc,command=circle).pack()
shp3=Button(fr3,text="Triangular",height=200,width=200,image=shptr,command=triangle).pack()
shp4=Button(fr3,text="Square",height=200,width=200,image=shpsq,command=rectangle).pack()
shp5=Button(fr3,text="Line",height=200,width=200,compound=LEFT,image=shpl,command=line).pack()


sc.deiconify()
sc.mainloop()
</code></pre>

<p>Here is my code after correction</p>

<pre><code>import tkinter
from tkinter import *
import turtle
import sys
sc=Tk()
sc.geometry("1000x1000+100+100")

var= IntVar()
pensize=StringVar()
angle=StringVar()
radius=StringVar()
lenght=StringVar()

#FRAMES
fr1=Frame(sc,height=200,width=200,bd=4,bg="light green",takefocus="",relief=SUNKEN)
fr1.grid(row=0,column=0,sticky=(N,E,W,S))
 #FR2
fr2=Frame(sc,height=200,width=200,bd=4,bg="light green",takefocus="",relief=SUNKEN)
fr2.grid(row=1,column=0,sticky=(N,E,W,S))
 #FR3
fr3=Frame(sc,height=200,width=200,bd=4,bg="light green",takefocus="",relief=SUNKEN)
fr3.grid(row=2,column=0,sticky=(N,E,W,S))
 #FR4
fr4=Frame(sc,height=500,width=600,bd=4,bg="light green",takefocus="",relief=SUNKEN)
fr4.grid(row=2,column=2,sticky=(N,E,W,S))
 #FR5
fr5=Frame(sc,height=100,width=600,bd=4,bg="gray",takefocus="",relief=SUNKEN)
fr5.grid(row=1,column=2,sticky=(N,E,W,S))

#Canvas
canvas = Canvas(fr4,width=750, height=750)
canvas.pack()

#Turtle
turtle1=turtle.RawTurtle(canvas)
turtle1.color("blue")
turtle1.shape("turtle")

#Functions
def rectangle():
    turtle1.begin_fill()
    colorchoices()
    turtle1.pensize(int(pensize.get()))               
    for i in range(4):
        turtle1.forward(int(lenght.get()))
        turtle1.left(90)
    turtle1.end_fill()

def circle():
    turtle1.begin_fill()
    turtle1.pensize(int(pensize.get()))
    colorchoices()
    turtle1.circle(int(radius.get()))
    turtle1.end_fill()

def triangle():
    turtle1.begin_fill()
    colorchoices()
    turtle1.pensize(int(pensize.get()))
    turtle1.forward(int(lenght.get()))
    turtle1.left(120)
    turtle1.forward(int(lenght.get()))
    turtle1.left(120)
    turtle1.forward(int(lenght.get()))
    turtle1.end_fill()

def line100 ():
    turtle1.penup()
    turtle1.pensize(int(pensize.get()))
    turtle1.forward(int(lenght.get()))
    turtle1.pendown()

def linel90 ():
    turtle1.penup()
    turtle1.left(int(angle.get()))
    turtle1.pendown()

def liner90 ():
    turtle1.penup()
    turtle1.pensize(int(pensize.get()))
    turtle1.right(int(angle.get()))
    turtle1.pendown()

def linebc100 ():
    turtle1.penup()
    turtle1.begin_fill()
    colorchoices()
    turtle1.pensize(int(pensize.get()))
    turtle1.backward(int(lenght.get()))

    turtle1.end_fill()
    turtle1.pendown()

def line():

    turtle1.begin_fill()
    colorchoices()
    turtle1.pensize(int(pensize.get()))
    turtle1.forward(int(lenght.get()))
    turtle1.end_fill()

def colorchoices():
    selection=var.get()
    for i in range(8):
        if selection==1:
            turtle1.fillcolor("red")
        elif selection==2:
            turtle1.fillcolor("blue")
        elif selection==3:
            turtle1.fillcolor("purple")
        elif selection==4:
            turtle1.fillcolor("yellow")
        elif selection==5:
            turtle1.fillcolor("orange")
        elif selection==6:
            turtle1.fillcolor("green")    
        elif selection==7:
            turtle1.fillcolor("")


def clear():
    turtle1.clear()




but1=Button(fr1,text="Clear",command=clear).pack(side=LEFT)
# shapes
shpc=PhotoImage(file="D://python//Ä±mage/circle.png")
shptr=PhotoImage(file="D://python//Ä±mage/rectangular.png")
shpsq=PhotoImage(file="D://python//Ä±mage/square.png")
shpl=PhotoImage(file="D://python//Ä±mage/line.png")
shphep=PhotoImage(file="D://python//Ä±mage/shapes.png")

#Entry and labels
PenSize=Button(fr5,text="PenSize",font=("Helvetica",14),fg="black").grid(row=0,column=0,columnspan=1,sticky=W)
Angle=Button(fr5,text="Angle",font=("Helvetica",14),fg="black").grid(row=1,column=0,columnspan=1,sticky=W)
Radius=Button(fr5,text="Radius",font=("Helvetica",14),fg="black").grid(row=2,column=0,columnspan=1,sticky=W)
Lenght=Button(fr5,text="Lenght",font=("Helvetica",14),fg="black").grid(row=3,column=0,columnspan=1,sticky=W)
pensize=Entry(fr5)
angle=Entry(fr5)
radius=Entry(fr5)
lenght=Entry(fr5)
pensize.grid(row=0,column=1,columnspan=2,sticky=W)
angle.grid(row=1,column=1,columnspan=2,sticky=W)
radius.grid(row=2,column=1,columnspan=2,sticky=W)
lenght.grid(row=3,column=1,columnspan=2,sticky=W)



#optionmenu
ColorOption=Button(fr5,text="ColorOptions",font=("Helvetica",14),fg="black").grid(row=4,column=0,sticky=W)
R1 = Radiobutton(fr5, text="RED", variable=var, value=1,bg="red").grid(row=4,column=1,sticky=W)
R2 = Radiobutton(fr5, text="BLUE", variable=var, value=2,bg="blue").grid( row=4,column=2,sticky=W)
R3 = Radiobutton(fr5, text="PURPLE", variable=var, value=3,bg="purple").grid( row=4,column=3,sticky=W )
R4 = Radiobutton(fr5, text="YELLOW", variable=var, value=4,bg="yellow").grid( row=4,column=4,sticky=W)
R5 = Radiobutton(fr5, text="ORANGE", variable=var, value=5,bg="orange").grid( row=4,column=5,sticky=W )
R6 = Radiobutton(fr5, text="GREEN", variable=var, value=6,bg="green").grid( row=4,column=6,sticky=W)
R7 = Radiobutton(fr5, text="NO COLOR", variable=var, value=7).grid( row=4,column=7,sticky=W)

#Buttons
but1=Button(fr2,text="Forward",command=line100).grid(row=1,column=2,sticky=(N,E,W,S))
but1=Button(fr2,text="Backward",command=linebc100 ).grid(row=1,column=0,sticky=(N,E,W,S))
but1=Button(fr2,text="Turn90",command=linel90).grid(row=0,column=1,sticky=(N,E,W,S))
but1=Button(fr2,text="Turn(-90)",command=liner90).grid(row=2,column=1,sticky=(N,E,W,S))
#shp1=Label(fr5,text="SHAPES",image=shphep).pack(fill=X)
shp2=Button(fr3,text="Circle",height=200,width=200,image=shpc,command=circle).pack()
shp3=Button(fr3,text="Triangular",height=200,width=200,image=shptr,command=triangle).pack()
shp4=Button(fr3,text="Square",height=200,width=200,image=shpsq,command=rectangle).pack()
shp5=Button(fr3,text="Line",height=200,width=200,compound=LEFT,image=shpl,command=line).pack()


sc.deiconify()
sc.mainloop()
</code></pre>

python tkinter turtle-graphics