turtle kütüphanesini tkinte arayüzü ile kulanmayı denedimde çok işlevsel olmadı bir yardım ederseniz
from tkinter import *
from tkinter.ttk import *
from turtle import *
class Main_Stuff(Tk):
def __init__(self):
Tk.__init__(self)
self.myspeed=6
self.ıdlist = []
self.geometry("1366x768")
self.canvas = Canvas(self,height=490,width=585)
self.cframe = Frame(self.canvas)
self.xs = Scrollbar(self,orient=HORIZONTAL,command=self.canvas.xview)
self.ys = Scrollbar(self,orient=VERTICAL,command=self.canvas.yview)
self.canvas.configure(xscrollcommand=self.xs.set)
self.canvas.configure(yscrollcommand=self.ys.set)
self.canvas.grid(column=5, row=4,rowspan=1,sticky='N')
self.canvas.create_window((0,0),window=self.cframe,anchor='center')
self.screen =TurtleScreen(self.canvas)
self.fd = RawTurtle(self.canvas)
self.my_loob_event()
self.my_events()
self.entries()
self.buttons()
self.labels()
self.move_and_draw(args='')
self.difference_widget()
self.grids()
self.bind_event()
def my_loob_event(self):
self.check_value = IntVar()
self.loop_value = IntVar()
self.check = Checkbutton(self, text='Loop', variable=self.check_value, command=self.command_funtion)
self.check.grid(column=0, row=4, sticky='N')
print(self.check_value.get())
def command_funtion(self):
self.label7 = Label(text='please select the operations to be repeated')
self.label7.grid(column=1,row=4,sticky='N',columnspan =4)
self.listwidget = Listbox(self)
self.listwidget.grid(column=1,row=4,columnspan =4,rowspan=1,sticky='N',pady=20)
self.loopentry = Entry(width=5,textvariable=self.loop_value)
self.loopentry.grid(column=2,row=4,columnspan=1,sticky='NE',pady=186,ipadx=0,ipady=1)
self.loopbutton = Button(text='Run',command=lambda:[self.move_and_draw(29)])
self.loopbutton.grid(column=3,row=4,columnspan=1,sticky='NE',pady=185,ipadx=5)
print(self.check_value.get())
def bind_event(self):
self.bind('<Configure>', self.on_frame_resized)
self.bind_all()
def loob(self):
print("hello")
def on_frame_resized(self, event=None):
self.canvas.configure(scrollregion=self.canvas.bbox("all"))
def my_events(self):
self.screen.onclick(self.do_it)
self.fd.ondrag(self.fd.goto)
def do_it(self,x,y):
if self.fd.isdown():
self.fd.penup()
self.fd.hideturtle()
self.fd.goto(x,y)
self.xcor = self.fd.xcor()
self.ycor = self.fd.ycor()
self.xcorL.set(int(self.xcor))
self.ycorL.set(int(self.ycor))
self.fd.undo()
self.fd.showturtle()
self.fd.pendown()
else:
self.fd.hideturtle()
self.fd.goto(x, y)
self.xcor = self.fd.xcor()
self.ycor = self.fd.ycor()
self.xcorL.set(int(self.xcor))
self.ycorL.set(int(self.ycor))
self.fd.undo()
self.fd.showturtle()
self.fd.penup()
def entries(self):
self.distance = StringVar()
self.angle = StringVar()
self.radius =IntVar()
self.cangle =IntVar()
self.step = IntVar()
self.dotsize =IntVar()
self.psize = IntVar()
self.pen_size = IntVar()
self.xcoordinate = StringVar()
self.ycoordinate = StringVar()
self.entry1 = Entry(width=5,textvariable=self.distance)
self.entry2 = Entry(width=5,textvariable=self.angle)
self.entry3 = Entry(width=5,textvariable=self.xcoordinate)
self.entry4 = Entry(width=5,textvariable=self.ycoordinate)
self.entry5 = Entry(width=5,textvariable=self.radius)
self.entry6 = Entry(width=5,textvariable=self.cangle)
self.entry7 = Entry(width=5,textvariable=self.step)
self.entry8 = Entry(width=5,textvariable=self.dotsize)
self.entry9 = Entry(width=5,textvariable=self.psize)
self.entry10 = Entry(width=5,textvariable=self.pen_size)
def buttons(self):
self.my_value = IntVar()
self.my_value.set(1)
self.buton1 = Button(text='Forward',command=lambda:[self.move_and_draw(1)])
self.buton2 = Button(text='Backward',command=lambda:[self.move_and_draw(2)])
self.buton3= Button(text='Left',command=lambda:self.move_and_draw(3))
self.buton4 = Button(text='Right',command=lambda:self.move_and_draw(4))
self.buton5 = Button(text='Go To',command=lambda:self.move_and_draw(5))
self.buton6= Button(text='Go --> x',command=lambda :self.move_and_draw(6))
self.buton7= Button(text='Go --> y',command=lambda :self.move_and_draw(7))
self.buton8= Button(text='Set Heading',command=lambda :self.move_and_draw(8))
self.buton9= Button(text='Home',command=lambda :self.move_and_draw(9))
self.buton10= Button(text='Circle',command=lambda :self.move_and_draw(10))
self.buton11= Button(text='Polygone',command=lambda :self.move_and_draw(11))
self.buton12= Button(text='Dot Size',command=lambda :self.move_and_draw(12))
self.buton13= Button(text='Stamp',command=lambda :self.move_and_draw(13))
self.buton14= Button(text='Clear Stamp',command=lambda :self.move_and_draw(14))
self.buton15= Button(text='Undo',command=lambda :self.move_and_draw(15))
self.buton16= Button(text='Speed Up',command=lambda :self.move_and_draw(16))
self.buton17= Button(text='Speed Down',command=lambda :self.move_and_draw(17))
self.buton18= Radiobutton(self,variable=self.my_value,value=2,text='Pen Up',command=lambda :self.move_and_draw(18))
self.buton19= Radiobutton(self,variable=self.my_value,text='Pen Down',command=lambda :self.move_and_draw(19))
self.buton20= Button(text='Pen Size',command=lambda :self.move_and_draw(20))
self.buton21= Button(text='Pen Color',command=lambda :self.move_and_draw(21))
self.buton22= Button(text='Reset',command=lambda :self.move_and_draw(22))
self.buton23 = Button(text='Hide Pen', command=lambda: self.move_and_draw(23))
self.buton24 = Button(text='Show Pen', command=lambda: self.move_and_draw(24))
self.buton25 = Button(text='Eraser', command=lambda: self.move_and_draw(25))
self.buton26 = Button(text='Canvas Background', command=lambda: self.move_and_draw(26))
self.buton27 = Button(text='Pen Shape', command=lambda: self.move_and_draw(27))
self.buton28 = Button(text='Dot Color',command=lambda: self.move_and_draw(28))
def labels(self):
self.xcorL =StringVar()
self.ycorL =StringVar()
self.label1 = Label(text='Distance :')
self.label2 = Label(text='Angle :')
self.label3 = Label(text='x coordinate :')
self.label4 = Label(text='y coordinate :')
self.label5 = Label(textvariable=self.xcorL)
self.label6 = Label(textvariable=self.ycorL)
self.label7 = Label(text='Radius :')
self.label8 = Label(text='Cirle Angle :')
self.label9 = Label(text='Polygon Steps :')
self.label10 = Label(text='Dot Size :')
self.label11 = Label(text='Dot Colors')
self.label12 = Label(text='Polygone edge length :')
self.label13 = Label(text='Pen Size :')
self.label14 = Label(text='Pen Colors')
def difference_widget(self):
self.shapes=("arrow", "turtle", "circle", "square", "triangle", "classic")
self.colors=("White","Yellow","Blue","Red","Green","Black","Brown","Azure","Ivory","Teal","Silver","Purple","Navy","Gray","Orange","Maroon","Aquamarine","Coral","Fuchsia","Wheat","Lime","Crimson" ,"Khaki","pink","Magenta","Plum","Olive","Cyan")
self.sb1 = Spinbox(self,values=self.colors)
self.sb2 = Spinbox(self,values=self.colors)
self.sb3 = Spinbox(self,values=self.colors)
self.sb4= Spinbox(self,values=self.shapes)
def move_and_draw(self,args):
if args==1:
if self.check_value.get() == 1:
self.listwidget.insert(0,'forward '+str(self.d_value))
self.listwidget.selection_handle(self.loob())
self.fd.speed(self.myspeed)
self.d_value = float(self.distance.get())
self.fd.forward(self.d_value)
self.xcor = self.fd.xcor()
self.ycor = self.fd.ycor()
self.xcorL.set(int(self.xcor))
self.ycorL.set(int(self.ycor))
if args==2:
self.fd.speed(self.myspeed)
self.d_value = float(self.distance.get())
self.fd.backward(self.d_value)
self.xcor = self.fd.xcor()
self.ycor = self.fd.ycor()
self.xcorL.set(int(self.xcor))
self.ycorL.set(int(self.ycor))
if args==3:
self.a_value = float(self.angle.get())
self.fd.left(self.a_value)
self.xcor = self.fd.xcor()
self.ycor = self.fd.ycor()
self.xcorL.set(int(self.xcor))
self.ycorL.set(int(self.ycor))
if args==4:
self.a_value = float(self.angle.get())
self.fd.right(self.a_value)
self.xcor = self.fd.xcor()
self.ycor = self.fd.ycor()
self.xcorL.set(int(self.xcor))
self.ycorL.set(int(self.ycor))
if args==5:
self.xT = int(self.xcoordinate.get())
self.yT =int(self.ycoordinate.get())
self.fd.speed(self.myspeed)
self.fd.goto(self.xT,self.yT)
self.xcor = self.fd.xcor()
self.ycor = self.fd.ycor()
self.xcorL.set(self.xcor)
self.ycorL.set(int(self.ycor))
if args == 6:
self.fd.speed(self.myspeed)
self.xT = int(self.xcoordinate.get())
self.fd.setx(self.xT)
self.xcor = self.fd.xcor()
self.xcorL.set(self.xcor)
if args == 7:
self.fd.speed(self.myspeed)
self.yT = int(self.ycoordinate.get())
self.fd.sety(self.yT)
self.ycor = self.fd.ycor()
self.ycorL.set(int(self.ycor))
if args == 8:
self.a_value = float(self.angle.get())
self.fd.setheading(self.a_value)
if args == 9:
self.fd.home()
self.fd.speed(self.myspeed)
self.xcor = self.fd.xcor()
self.ycor = self.fd.ycor()
self.xcorL.set(int(self.xcor))
self.ycorL.set(int(self.ycor))
if args ==10:
self.fd.speed(self.myspeed)
self.rad =int(self.radius.get())
self.circleangle =self.cangle.get()
self.fd.circle(self.rad,self.circleangle)
self.xcor = self.fd.xcor()
self.ycor = self.fd.ycor()
self.xcorL.set(int(self.xcor))
self.ycorL.set(int(self.ycor))
if args == 11:
self.fd.speed(self.myspeed)
self.mypsize =int(self.psize.get())
self.Pstep= self.step.get()
self.fd.circle(self.mypsize,steps=self.Pstep)
self.xcor = self.fd.xcor()
self.ycor = self.fd.ycor()
self.xcorL.set(int(self.xcor))
self.ycorL.set(int(self.ycor))
if args == 12:
self.mydotsize = self.dotsize.get()
self.fd.dot(self.mydotsize)
if args == 13:
self.i=-1
self.i += 1
self.ıdlist.insert(self.i,self.fd.stamp())
if args ==14:
self.i =0
self.fd.clearstamp(self.ıdlist[self.i])
self.ıdlist.pop(self.i)
if args ==15:
self.fd.undo()
self.xcor = self.fd.xcor()
self.ycor = self.fd.ycor()
self.xcorL.set(int(self.xcor))
self.ycorL.set(int(self.ycor))
if args ==16:
self.myspeed += 1
self.fd.speed(self.myspeed)
print(self.myspeed)
if args ==17:
self.myspeed -= 1
if self.myspeed <= 0:
self.myspeed = 1
self.fd.speed(self.myspeed)
print(self.myspeed)
if args ==18:
self.fd.penup()
if args ==19:
self.fd.down()
if args ==20:
self.my_pen_size = self.pen_size.get()
self.fd.pensize(self.my_pen_size)
if args ==21:
self.mycolor=self.sb2.selection_get()
self.fd.pencolor(self.mycolor)
if args == 22:
self.fd.reset()
if args == 23:
self.fd.hideturtle()
if args == 24:
self.fd.showturtle()
if args ==25:
self.fd.pencolor('White')
if args ==26:
self.mycolor=self.sb3.selection_get()
self.canvas.configure(bg=self.mycolor)
if args ==27:
self.myshape = self.sb4.selection_get()
self.fd.shape(name=self.myshape)
if args ==28:
self.mydotsize = self.dotsize.get()
self.mycolor = self.sb1.selection_get()
self.fd.dot(self.mycolor)
self.fd.dot(self.mydotsize,self.mycolor)
if args == 29:
pass
def grids(self):
self.entry1.grid(column=1,row=0,sticky='W')
self.entry2.grid(column=1,row=1,sticky='W')
self.entry3.grid(column=2,row=2,sticky="S")
self.entry4.grid(column=2,row=3,sticky="N")
self.entry5.grid(column=1, row=5)
self.entry6.grid(column=1, row=6)
self.entry7.grid(column=1, row=8)
self.entry8.grid(column=9,row=0,sticky='WE')
self.entry9.grid(column=1, row=7)
self.entry10.grid(column=9, row=1,sticky='E')
self.buton1.grid(column=2,row=0)
self.buton2.grid(column=3,row=0)
self.buton3.grid(column=2,row=1)
self.buton4.grid(column=3,row=1)
self.buton5.grid(column=4,row=2,sticky="S")
self.buton6.grid(column=3,row=2,sticky="S")
self.buton7.grid(column=3,row=3,sticky="N")
self.buton8.grid(column=4,row=1)
self.buton9.grid(column=4,row=0)
self.buton10.grid(column=2,row=5)
self.buton11.grid(column=2,row=7)
self.buton12.grid(column=8,row=0)
self.buton13.grid(column=6,row=5)
self.buton14.grid(column=6,row=6)
self.buton15.grid(column=8,row=6)
self.buton16.grid(column=8,row=2)
self.buton17.grid(column=8,row=3)
self.buton18.grid(column=5,row=7)
self.buton19.grid(column=5,row=8)
self.buton20.grid(column=8,row=1)
self.buton21.grid(column=6,row=1,ipadx=20)
self.buton22.grid(column=8,row=5)
self.buton23.grid(column=7,row=6)
self.buton24.grid(column=7,row=5)
self.buton25.grid(column=7,row=7)
self.buton26.grid(column=6,row=3,sticky='N')
self.buton27.grid(column=6,row=2,ipadx=20,sticky='N')
self.buton28.grid(column=6,row=0,ipadx=20)
self.label1.grid(column=0,row=0)
self.label2.grid(column=0,row=1)
self.label3.grid(column=0,row=2,sticky="S")
self.label4.grid(column=0,row=3,sticky="N")
self.label5.grid(column=1,row=2,sticky="S")
self.label6.grid(column=1,row=3,sticky="N")
self.label7.grid(column=0, row=5)
self.label8.grid(column=0, row=6)
self.label9.grid(column=0, row=8)
self.label12.grid(column=0, row=7)
self.sb1.grid(column=7,row=0)
self.sb2.grid(column=7,row=1)
self.sb3.grid(column=7,row=3,sticky='N')
self.sb4.grid(column=7,row=2,sticky='N')
Main_Stuff = Main_Stuff()
Main_Stuff.mainloop()