0

I have a project about L-systems. I tried to add a turtle which prints L-systems; however, canvas does not expand, unlike a text field. My text field is expanding great with a scrollbar when I print more text. However, the turtle is stuck in the canvas. I am really stuck.

frame2 = tki.Frame(frame, bg='yellow', width=810, height=510)
frame2.pack()
frame2.place(x=500,y=5)
cv = Canvas(frame2, width=2000, height=2000)
cv.place(x=0, y=0)

screen = turtle.TurtleScreen(cv)
t = turtle.RawTurtle(screen)

hbar=Scrollbar(frame2,orient=HORIZONTAL)
hbar.pack(side=BOTTOM,fill=X)
hbar.config(command=cv.xview)
vbar=Scrollbar(frame2,orient=VERTICAL)
vbar.pack(side=RIGHT,fill=Y)
vbar.config(command=cv.yview)
cv.config(width=800,height=500)
cv.config(xscrollcommand=hbar.set, yscrollcommand=vbar.set)
cv.pack(side=LEFT,expand=True,fill=BOTH)
cdlane
  • 40,441
  • 5
  • 32
  • 81
vrd.gn
  • 198
  • 1
  • 18
  • don't use `pack()` and `place()` at the same time - they are two different "layout managers" – furas Dec 18 '17 at 03:09
  • create minimal working example so we could run it and see your problem. – furas Dec 18 '17 at 03:12
  • canas doesn't expand because it doesn't have this functionality - you may have to do it manually. – furas Dec 18 '17 at 03:16
  • Thank you for your time I will keep these in my mind. I have a fractal structure which expands out of the frame, that part I am not able to see the full picture while printing with the turtle. ScrolledCanvas is not working as well. – vrd.gn Dec 18 '17 at 04:34
  • scrolled canvas is scrolled only when you use scrollbars or when you write code which will scroll it. When you draw with turtle then you could check position and scroll canvas. – furas Dec 18 '17 at 05:04
  • Can I zoom in or zoom out by getting turtle's cordinates ? – vrd.gn Dec 18 '17 at 19:11
  • did you check in google ? ie. [Adding Zooming in and out with a Tkinter Canvas Widget?](https://stackoverflow.com/questions/5436810/adding-zooming-in-and-out-with-a-tkinter-canvas-widget) – furas Dec 18 '17 at 19:25

1 Answers1

1

If I understand your question correctly, why doesn't the ScrolledCavas that the turtle library provides for this purpose work for you:

EDIT: I've started the canvas size at the frame size and added the reset() method of ScrolledCanvas to expand the canvas dynamically:

import tkinter as tk
from turtle import TurtleScreen, RawTurtle, ScrolledCanvas

size = 100
canvsize = 300

root = tk.Tk()
root.geometry('600x500')

frame = tk.Frame(root, width=300, height=300)
frame.pack()
frame.place(x=50, y=50)

canvas = ScrolledCanvas(frame, canvwidth=canvsize, canvheight=canvsize)
canvas.pack(side=tk.LEFT)

screen = TurtleScreen(canvas)
screen.bgcolor('yellow')

turtle = RawTurtle(screen, visible=False)
turtle.dot(size, "green")

def expand():
    global canvsize, size

    if size < 800:
        size += 10
        if size > canvsize:
            canvsize += 100
            canvas.reset(canvwidth=canvsize, canvheight=canvsize)

        turtle.dot(size, "green")
        screen.ontimer(expand, 100)

screen.ontimer(expand, 100)

screen.mainloop()
cdlane
  • 40,441
  • 5
  • 32
  • 81
  • Thank you for your time. You are so close what I mean. The problem is that I wanted to observe the dot growing from 100 to 800. In other words, I would like to create a screen which does not have a scrollbar but when the turtle begins to prints and attempts to exceed frame sizes, the frame should be expanded with scrollbars. Like a text box... – vrd.gn Dec 18 '17 at 19:10
  • @VuralErdogan, I've reworked it so it does not have a scroll bar initially but adds them as the image expands past the horizontal and vertical edges of the frame. Probably not perfect but simple and uses only turtle `ScrolledCanvas`. – cdlane Dec 18 '17 at 19:45
  • Oh! that's exactly what I try to do. Thank you a lot. I will use your technique for my project. – vrd.gn Dec 18 '17 at 19:58