def draw(r=2): root = tk.Tk() canvas = turtle.ScrolledCanvas(root) canvas.pack(expand=True, fill='both') #wn = turtle.Screen() Body.Screens.append(root) turt = turtle.RawTurtle(canvas) turt.clear() turt.ht() turt.up() Body.circles(turt,r)
def __init__(self): self.__root = tk.Tk() self.__canvas = turtle.ScrolledCanvas(self.__root, width=1000, height=600) self.__canvas.pack() self.__screen = turtle.TurtleScreen(self.__canvas) self.__turtle = turtle.RawTurtle(self.__screen) self.__ship = turtle.RawTurtle(self.__screen) self.__screen.setworldcoordinates(-500, -500, 500, 500) self.build_ship()
def makeGraphFrame(self, root): turtle._Screen._root = root self.canvwidth = 850 self.canvheight = 850 turtle._Screen._canvas = self._canvas = canvas = turtle.ScrolledCanvas( root, 800, 550, self.canvwidth, self.canvheight) canvas.adjustScrolls() self.screen = _s_ = turtle.Screen() turtle.TurtleScreen.__init__(_s_, _s_._canvas) self.scanvas = _s_._canvas turtle.RawTurtle.screens = [_s_] return canvas
def makeGraphFrame(self, root): turtle._Screen._root = root self.canvwidth = 1000 self.canvheight = 800 turtle._Screen._canvas = self._canvas = canvas = turtle.ScrolledCanvas( root, 800, 600, self.canvwidth, self.canvheight) canvas.adjustScrolls() canvas._rootwindow.bind('<Configure>', self.onResize) canvas._canvas['borderwidth'] = 0 self.screen = _s_ = turtle.Screen() turtle.TurtleScreen.__init__(_s_, _s_._canvas) self.scanvas = _s_._canvas turtle.RawTurtle.screens = [_s_] return canvas
def main(): def start(): print("Start") #TODO write root = tkinter.Tk() root.title("Patience") cv = turtle.ScrolledCanvas(root, 600, 600, 600, 600) cv.tk_setPalette(background="green") cv.pack(side=tkinter.LEFT) bar = tkinter.Menu(root) fileMenu = tkinter.Menu(bar, tearoff=0) fileMenu.add_command(label="Start", command=start) bar.add_cascade(label="File", menu=fileMenu) root.config(menu=bar)
def __init__(self, root, canvwidth, canvheight, winwidth, winheight): import turtle Tkinter.Canvas.__init__(self, root) turtle._Screen._root = root self.turtle = turtle self.canvwidth = 850 self.canvheight = 850 turtle._Screen._canvas = self._canvas = canvas = _turtle.ScrolledCanvas( root, winwidth, winheight, canvwidth, canvheight) canvas.adjustScrolls() self.screen = _s_ = turtle.Screen() turtle.TurtleScreen.__init__(_s_, _s_._canvas) self.scanvas = _s_._canvas turtle.RawTurtle.screens = [_s_] self.canvas = canvas
def draw_star(self): WIDTH, HEIGHT = 2560, 1440 root = tk.Tk() canvas = turtle.ScrolledCanvas(root, width=WIDTH, height=HEIGHT) canvas.pack() screen = turtle.TurtleScreen(canvas) screen.bgcolor('black') t = turtle.RawTurtle(screen, visible=False) t.speed('fastest') pen_color = 'blue' t.pencolor(pen_color) t.penup() x = 1100 # size of star myStart = (x / 2, x / 3.5) t.setpos(myStart) t.pendown() n = 62 # sets value for angle of each point pointCount = 0 run = True while run == True: t.rt(180 - n) t.fd(x) pointCount += 1 if t.distance(myStart) < 1.0: run = False screen.mainloop()
def run_draw(h,duration,r=2): root = tk.Tk() canvas = turtle.ScrolledCanvas(root) canvas.pack(expand=True, fill='both') #wn = turtle.Screen() Body.Screens.append(root) turt = turtle.RawTurtle(canvas) turt.clear() turt.ht() turt.up() turt.speed(0) #rgb = (255,255,255) #turt.colormode(255) #turt.pencolor(.955,.955,.955) steps = duration // h for i in range(steps): for j in Body.bodies: j.update(h) if i%10==0: Body.circles(turt,r)
def create_widgets(self): # 面板:功能 frameFunction = tk.Frame(self, width=500) frameFunction.pack(side='left', fill='both') # 画布 # 画布大小决定窗口大小,超出屏幕区域时不会出现滚动条 self.canvas = tt.ScrolledCanvas(self, width=10000, height=10000) self.canvas.pack(side='right', fill='y') # 按钮:画三角形 self.btn_draw_trangle = tk.Button(frameFunction, text='画三角形', command=self.cmd_draw_trangle) self.btn_draw_trangle.pack(side="top", fill='both') # 按钮:退出 self.btn_quit = tk.Button(frameFunction, text='退出', command=self.cmd_quit) self.btn_quit.pack(side="bottom", fill='x')
import Tkinter, turtle, random, time root = Tkinter.Tk() root.title("Pong") screen_w = 700 screen_h = 500 left_x = -screen_w / 2 + 4 right_x = screen_w / 2 - 11 shot_vx = 20 ball_vx = 10 min_ball_vy = 1 max_ball_vy = 15 left_score_x = -screen_w / 2 + 14 right_score_x = screen_w / 2 - 29 score_y = screen_h / 2 - 30 score_font = ('Arial', 16, 'normal') cv = turtle.ScrolledCanvas(root, screen_w, screen_h) cv.pack() screen = turtle.TurtleScreen(cv) class Ball(turtle.RawTurtle): def __init__(self, canvas): turtle.RawTurtle.__init__(self, canvas) self.hideturtle() self.penup() self.color('red') for i in range(24): self.getscreen().register_shape('hface/hface' + str(i) + '.gif') self.shape('hface/hface0.gif') self.snum = 0 self.sdir = 1
es.msgbox("NameError: name " + splited[0] + "' is not defined", 'Error') elif splited[0] == 'down': t2.pendown() elif splited[0] == 'up': t2.penup() elif splited[0] == 'clear': t2.clear() else: es.msgbox("NameError: name " + splited[0] + "' is not defined", 'Error') r = tu._Root() r.set_geometry(800, 800, 0, 0) cv2 = tu.ScrolledCanvas(r) cv2.pack(expand=True, fill=tk.BOTH) cv2.reset(400, 4000) t1 = tu.RawPen(cv2) cv3 = tu.ScrolledCanvas(r) cv3.pack(expand=True, fill=tk.BOTH) cv3.reset(400, 400) t2 = tu.RawPen(cv3) t2.shape('turtle') t1.hideturtle() t1.penup() t1.goto(-350, 100) t1.color('green') t1.write(''' _____ __ | __ \ / _|
def draw_all_designs(self): color_selection = [ '#2e4aff', '#000000', '#ffffff' ] # background, quadrant line color, star line color # canvas and turtle setup WIDTH, HEIGHT = 2560, 1440 root = tk.Tk() canvas = turtle.ScrolledCanvas(root, width=WIDTH, height=HEIGHT) canvas.pack() screen = turtle.TurtleScreen(canvas) # screen.bgcolor('black') screen.bgcolor(color_selection[0]) t = turtle.RawTurtle(screen, visible=False) my_speed = 10 # my_speed = 'fastest' # uncomment for testing t.speed(my_speed) # begin MathQuadrant t.pencolor(color_selection[1]) # color for MathQuadrant pen box_width = 10 amplitude = 700 # max height and width of one quadrant lines_to_draw = amplitude / box_width # Whole image drawn X = 0 Y = amplitude negX = 0 negY = -amplitude total_lines = 0 # used only if a count of total lines used is desired count = 0 while count <= lines_to_draw: t.setpos(0, Y) t.pendown() t.goto(X, 0) t.goto(0, -Y) t.penup() X += box_width Y -= box_width t.setpos(0, negY) t.pendown() t.goto(negX, 0) t.goto(0, -negY) t.penup() negX -= box_width negY += box_width count += 1 total_lines += 4 # drawing complete total_lines -= 4 # accounts for redrawing of x and y axes print(f'This shape has {total_lines} lines.') # begin Star t.speed(my_speed) t.pencolor(color_selection[2]) t.penup() x = 1100 # size of star myStart = (x / 2, x / 3.5) t.setpos(myStart) t.pendown() n = 62 # sets value for angle of each point pointCount = 0 run = True while run == True: t.rt(180 - n) t.fd(x) pointCount += 1 if t.distance(myStart) < 1.0: run = False print(f'This star has {pointCount} points.') screen.mainloop()
import json import sys import Tkinter as tk import numpy as np import turtle app = tk.Tk() cv = turtle.ScrolledCanvas(app) cv.pack() screen = turtle.TurtleScreen(cv) screen.screensize(1500, 1500) lam = turtle.RawTurtle(screen) def pars(): inputFile = open('data.json') data = json.load(inputFile) tab_dist = [] i = int(input('choose the number you want ')) if i < 0 or i >= len(data["experiments"]): print("Not a valid choice") sys.exit(1) arrayToRead = data["experiments"][i]["readings"] for k in range(0, len(arrayToRead)): time = 0 if k == 0: time = data["experiments"][i]["readings"][k]["timestamp"] else:
def draw_dfa(dfa): ######################################################### import turtle import tkinter root = tkinter.Tk() root.geometry('500x500-5+40') #added by me cv = turtle.ScrolledCanvas(root, width=1500, height=900) cv.pack() screen = turtle.TurtleScreen(cv) screen.screensize(3000, 1500) #added by me t = turtle.RawTurtle(screen) #t.hideturtle() #t.circle(100) #t = turtle.Turtle() # currne position (0,0), #above is +ve, below is negatibe #dfa = {'a': [[0, 1], [1, 1], [2, 1]], 'b': [[0, 0], [1, 2], [2, 0]]} #dfa = {'a': [[0, 1], [1, 'D'], [2, 'D'], [3, 3], ['D', 'D']], 'b': [[0, 'D'], [1, 2], [2, 3], [3, 3], ['D', 'D']]} flag = 0 for i in range(len(dfa)): for j in range(len(dfa[list(dfa.keys())[0]])): if dfa[list(dfa.keys())[i]][j][0] == "D": flag = 1 dfa[list( dfa.keys())[i]][j][0] = len(dfa[list(dfa.keys())[i]]) - 1 if dfa[list(dfa.keys())[i]][j][1] == "D": dfa[list( dfa.keys())[i]][j][1] = len(dfa[list(dfa.keys())[i]]) - 1 colors = [ "red", "green", "purple", "red", "green", "blue", "red", "green", "blue", "orange" ] space = 15 arrow = {} radius = 15 * len(dfa[list(dfa.keys())[0]]) t.penup() t.goto(-radius * 2, radius) t.pendown() #t.forward(radius) t.goto(-radius, radius) t.stamp() t.penup() t.goto(0, 0) t.pendown() for i in range(len(dfa[list(dfa.keys())[0]])): if i == len(dfa[list(dfa.keys())[0]]) - 1 and flag == 1: t.circle(radius) t.write("Dead", align="center", font=("Arial", 12, "normal")) else: if i == len(dfa[list(dfa.keys())[0]]) - 1 or ( i == len(dfa[list(dfa.keys())[0]]) - 2 and flag == 1): t.circle(radius) t.penup() t.goto((i) * radius * 3, 10) t.pendown() t.circle(radius - 10) t.write("Q" + str(i), align="center", font=("Arial", 12, "normal")) else: t.circle(radius) t.write("Q" + str(i), align="center", font=("Arial", 12, "normal")) t.color(colors[i]) #t.write("Q") #print(t.position()) arrow[i] = (int(t.position()[0]), int(t.position()[1] + radius * 2)) t.penup() t.goto((i + 1) * radius * 3, 0) t.pendown() t.color(colors[-1]) #t.speed(1) t.right(90) for j in range(len(dfa[list(dfa.keys())[0]])): for k in range(len(dfa[list(dfa.keys())[0]])): ## for a if dfa[list(dfa.keys())[0]][k][0] == j: t.penup() t.goto(arrow[j][0] + k * space, arrow[j][1]) t.pendown() t.goto(arrow[j][0] + k * space, arrow[j][1] + (j + 1) * 40) t.write(list(dfa.keys())[0], align="center", font=("Arial", 12, "normal")) t.goto( arrow[dfa[list(dfa.keys())[0]][k][1]][0] + k * space + 8, arrow[j][1] + (j + 1) * 40) t.goto(arrow[dfa[list(dfa.keys())[0]][k][1]][0] + k * space, arrow[j][1]) t.stamp() else: continue t.color(colors[-2]) t.right(180) for j in range(len(dfa[list(dfa.keys())[0]])): for k in range(len(dfa[list(dfa.keys())[0]])): ## for a if dfa[list(dfa.keys())[1]][k][0] == j: t.penup() t.goto(arrow[j][0] + k * space, arrow[j][1] - 2 * radius) t.pendown() t.goto(arrow[j][0] + k * space, arrow[j][1] - 2 * radius + (j + 1) * -40) #t.penup() #t.goto(arrow[j][0] + k*space, arrow[j][1]- 2*radius + (j+1)*-55) t.write(list(dfa.keys())[1], align="right", font=("Arial", 12, "normal")) #t.goto(arrow[j][0] + k*space, arrow[j][1]- 2*radius + (j+1)*-40) #t.pendown() t.goto( arrow[dfa[list(dfa.keys())[1]][k][1]][0] + k * space + 8, arrow[j][1] - 2 * radius + (j + 1) * -40) t.goto(arrow[dfa[list(dfa.keys())[1]][k][1]][0] + k * space, arrow[j][1] - 2 * radius) t.stamp() else: continue root.mainloop()
import turtle from _tkinter import * from itertools import cycle root = Tk() root.title("World Populaton 2019") #root.geometry('900x900-5+40') #added by me cv = turtle.ScrolledCanvas(root, width=1024, height=768) cv.pack() coutryData = [] asiacountry = [] northamericacountry = [] southamericacountry = [] africacountry = [] europecountry = [] oceancountry = [] chinaPopu = 0 style = ('Courier', 12) def loadCoutryData(): rowcount = 1 with open('WorldPopulationData2019.txt') as file: for line in file: rowcount = rowcount + 1 if (rowcount < 3): continue line = line.strip('\n') line = line.split('; ')
def draw_quadrants(self): color_selection = [ '#2e4aff', '#000000', '#ffffff' ] # background, quadrant line color, star line color # canvas and turtle setup WIDTH, HEIGHT = 2560, 1440 root = tk.Tk() canvas = turtle.ScrolledCanvas(root, width=WIDTH, height=HEIGHT) canvas.pack() screen = turtle.TurtleScreen(canvas) # screen.bgcolor('black') screen.bgcolor(color_selection[0]) t = turtle.RawTurtle(screen, visible=False) t.speed('fastest') # color for MathQuadrant pen t.pencolor(color_selection[1]) box_width = 10 amplitude = 700 # max height and width of one quadrant lines_to_draw = amplitude / box_width # Whole image drawn X = 0 Y = amplitude negX = 0 negY = -amplitude total_lines = 0 # used only if a count of total lines used is desired count = 0 while count <= lines_to_draw: t.setpos(0, Y) t.pendown() t.goto(X, 0) t.goto(0, -Y) t.penup() X += box_width Y -= box_width t.setpos(0, negY) t.pendown() t.goto(negX, 0) t.goto(0, -negY) t.penup() negX -= box_width negY += box_width count += 1 total_lines += 4 # drawing complete total_lines -= 4 # accounts for redrawing of x and y axes print(f'This shape has {total_lines} lines.') screen.mainloop()
def showOutput(result, ncu): global window, width, height, graph window2 = Toplevel(window) window2.title("GRAPH COLORING SIMULATION INPUT") window2.geometry("{0}x{1}+0+0".format(int(width * 0.7), int(height * 0.7))) window2.config(bg=rgb(255, 255, 255)) displayOutput = Label( window2, text="The number of colors used are only = {0}, observe properly". format(ncu)) displayOutput['font'] = myFont displayOutput['bg'] = rgb(255, 255, 255) displayOutput.pack() cv = turtle.ScrolledCanvas(window2) cv.pack(fill="both", expand=True) screen = turtle.TurtleScreen(cv) screen.screensize(5000, 5000) no_of_vertices = len(graph) angle = 360 / no_of_vertices shapeMaker = turtle.RawTurtle(screen) shapeMaker.hideturtle() shapeMaker.speed(100) shapeMaker.color(rgb(255, 255, 255), rgb(255, 255, 255)) mul = 1 while no_of_vertices > mul or mul % 10 != 0: mul += 1 d = mul * 10 vertex, vertexID = list(), list() for i in range(no_of_vertices): x, y = shapeMaker.position() vertex.append(turtle.RawTurtle(screen)) vertex[i].hideturtle() vertex[i].speed(100) vertex[i].color(rgb(255, 255, 255), rgb(255, 255, 255)) vertex[i].setpos(x, y) vertexID.append(turtle.RawTurtle(screen)) vertexID[i].hideturtle() vertexID[i].speed(100) vertexID[i].color(rgb(255, 255, 255), rgb(255, 255, 255)) vertexID[i].setpos(x, y) shapeMaker.left(angle) shapeMaker.fd(d) for i in range(no_of_vertices): vertex[i].color(result[i], result[i]) vertex[i].begin_fill() vertex[i].circle(20) vertex[i].end_fill() vertexID[i].color("black", "black") vertexID[i].write(i, False, "center", font=("Arial", 12, "bold")) drawEdges = list() k = 0 for i in range(len(graph)): for j in range(len(graph[i])): drawEdges.append(turtle.RawTurtle(screen)) drawEdges[k].hideturtle() drawEdges[k].speed(100) drawEdges[k].color(rgb(255, 255, 255), rgb(255, 255, 255)) x, y = vertex[i].position() drawEdges[k].setpos(x, y) k += 1 for i in range(no_of_vertices): vertex[i].color(result[i], result[i]) vertex[i].begin_fill() vertex[i].circle(20) vertex[i].end_fill() vertexID[i].color("black", "black") vertexID[i].write(i, False, "center", font=("Arial", 12, "bold")) k = 0 for i in range(len(graph)): for j in range(len(graph[i])): x, y = vertex[graph[i][j]].position() drawEdges[k].color(rgb(0, 0, 0), rgb(0, 0, 0)) drawEdges[k].goto(x, y) k += 1
def draw_snowman(snowman, initial_position=[100, 100]): """Draw a complete snowman (eyes,hat,nose,buttons,arms) and a tree""" #Build the window root = tk.Tk() root.geometry('500x500-5+40') cv = turtle.ScrolledCanvas(root, width=900, height=900) cv.pack() #Paint the background scr = turtle.TurtleScreen(cv) scr.bgcolor('#BFE2FF') #Initialize the Turtle, put it in canvas snowman = turtle.RawTurtle(scr) start = initial_position #Draw the 3 circles snowman.pen(fillcolor='white') for i in range(3): snowman.penup() snowman.goto(initial_position) snowman.pd() snowman.begin_fill() while True: snowman.left(2) snowman.forward(1) if int(snowman.heading()) == 180: diameter = snowman.pos()[1] - initial_position[1] if int(snowman.heading()) == 0: break snowman.end_fill() initial_position[1] += diameter #Draw the hat snowman.pu() snowman.goto(initial_position) snowman.pd() snowman.pen(fillcolor='purple') snowman.seth(0) snowman.begin_fill() snowman.forward(0.5 * diameter) snowman.left(90) snowman.forward(0.2 * diameter) snowman.left(90) snowman.forward(0.25 * diameter) snowman.right(90) snowman.forward(0.5 * diameter) snowman.left(90) snowman.forward(0.5 * diameter) snowman.left(90) snowman.forward(0.5 * diameter) snowman.right(90) snowman.forward(0.25 * diameter) snowman.left(90) snowman.forward(0.2 * diameter) snowman.left(90) snowman.forward(0.5 * diameter) snowman.end_fill() snowman.pu() #Draw the buttons initial_position[1] -= diameter snowman.width(5) for i in range(4): initial_position[1] -= 0.2 * diameter snowman.goto(initial_position) snowman.dot(6, 'green') initial_position[1] += 2 * diameter #Draw the nose snowman.pen(fillcolor='orange') initial_position[1] -= 0.7 * diameter snowman.right(90) snowman.goto(initial_position) snowman.stamp() #Draw the eyes initial_position[0] += 0.25 * diameter initial_position[1] += 0.25 * diameter snowman.goto(initial_position) snowman.width(5) snowman.dot(10, 'grey') initial_position[0] -= 0.5 * diameter snowman.goto(initial_position) snowman.dot(10, 'grey') #Draw the stick arms and fingers initial_position[0] -= 0.25 * diameter initial_position[1] -= 1.25 * diameter right_stick = [initial_position[0] + diameter, initial_position[1]] snowman.goto(initial_position) snowman.seth(135) snowman.width(2) snowman.pd() snowman.forward(diameter / 2) snowman.backward(diameter / 7) snowman.seth(235) snowman.forward(diameter / 7) snowman.backward(2 * diameter / 7) snowman.pu() snowman.goto(right_stick) snowman.pd() snowman.seth(45) snowman.width(2) snowman.pd() snowman.forward(diameter / 2) snowman.backward(diameter / 7) snowman.seth(135) snowman.forward(diameter / 7) snowman.backward(2 * diameter / 7) #Draw the tree snowman.pu() start[0] -= 2 * diameter start[1] -= diameter snowman.goto(start) snowman.seth(90) snowman.shape('triangle') snowman.shapesize(6, 6, 2) snowman.pen(fillcolor='brown') snowman.stamp() snowman.goto(start[0], start[1] + 60) snowman.pen(fillcolor='green') snowman.stamp() root.mainloop()
except ValueError: print("donner un entier!") #continue else: break print("le shema d'appareillage et d'instalation est le suivant ") root=Tk() wid= root.winfo_screenwidth() hei= root.winfo_screenheight() root.geometry('800x800-5+40') #added by me cv = turtle.ScrolledCanvas(root,width=wid,height=hei) cv.pack() screen = turtle.TurtleScreen(cv) screen.screensize(4500,1500) #added by me t = turtle.RawTurtle(screen) t.speed(0) t.color("red") t.forward(700) t.color("blue") t.pu()
def __init__(self,master): self.master=master b=tix.Balloon(self.master) self.tabcon=ttk.Notebook(self.master) self.pw=Frame(self.tabcon) self.tabcon.add(self.pw,text="Actions") self.pl=Frame(self.tabcon) self.tabcon.add(self.pl,text="Time") self.nb=Frame(self.tabcon) self.tabcon.add(self.nb,text="Loop") self.ia=Frame(self.tabcon) self.tabcon.add(self.ia,text="Objects") self.fg=Frame(self.tabcon) self.tabcon.add(self.fg,text="functions") self.df=Frame(self.tabcon) self.tabcon.add(self.df,text="key links") self.yu=Frame(self.tabcon) self.tabcon.add(self.yu,text="Screen") self.tabcon.grid(row=0,column=0,sticky="n") self.canvas = turtle.ScrolledCanvas(master = self.master) self.canvas.grid(row=0,column=1) self.screen=turtle.TurtleScreen(self.canvas) self.draw = turtle.RawTurtle(self.screen) self.screen.listen() self.draw.pu() self.objects={"Object1":self.draw} self.screen.onclick(self.listen) self.draw.ondrag(self.dragging) Button(self.pw,text="move upwards",command=self.up).grid() Button(self.pw,text="move downwards",command=self.down).grid() Button(self.pw,text="move right",command=self.right).grid() Button(self.pw,text="move left",command=self.left).grid() Button(self.pw,text="move forward",command=self.fwd).grid(row=4,column=0) Button(self.pw,text="move backward",command=self.bwd).grid(row=5,column=0) self.deg=Entry(self.pw) self.deg.grid(row=6,column=1) Button(self.pw,text="Rotate left",command=self.rotlt).grid(row=6,column=0) self.deg1=Entry(self.pw) self.deg1.grid(row=7,column=1) Button(self.pw,text="Rotate right",command=self.rotrt).grid(row=7,column=0) Button(self.pw,text="Show object",command=self.show).grid(row=8,column=0) Button(self.pw,text="Hide object",command=self.hide).grid(row=9,column=0) Button(self.pw,text="stamp",command=self.stamp).grid(row=10,column=0) Button(self.pw,text="clear previous stamp",command=self.clprestmp).grid(row=11) Button(self.pw,text="clear all stamps",command=self.clallstmp).grid(row=12) self.gotopos=Entry(self.pw) self.gotopos.grid(row=13,column=1) Button(self.pw,text="goto position",command=self.goto).grid(row=13,column=0) self.circpar=Entry(self.pw) self.circpar.grid(row=14,column=1) Button(self.pw,text="circle",command=self.circ).grid(row=14,column=0) b.bind_widget(self.circpar, msg="""Draw a circle with given radius. The center is radius units left of the turtle; extent – an angle – determines which part of the circle is drawn. If extent is not given, draw the entire circle. If extent is not a full circle, one endpoint of the arc is the current pen position. Draw the arc in counterclockwise direction if radius is positive, otherwise in clockwise direction. Finally the direction of the turtle is changed by the amount of extent. As the circle is approximated by an inscribed regular polygon, steps determines the number of steps to use. If not given, it will be calculated automatically. May be used to draw regular polygons. Enter the three parameters one after the other separated by commas. radius is compulsory.""") Button(self.pw,text="pen down",command=self.pendown).grid() Button(self.pw,text="pen up",command=self.penup).grid() Button(self.pw,text="Choose pen colour",command=lambda:self.colourchoose("pencolour")).grid() self.wo=Entry(self.pl) self.wo.grid(row=0,column=1) Button(self.pl,text="Wait for",command=self.wa).grid(row=0,column=0) self.delay=Entry(self.pl) self.delay.grid(row=1,column=1) Button(self.pl,text="set animation delay",command=self.dela).grid(row=1,column=0) self.speed=Entry(self.pl) self.speed.grid(row=2,column=1) Button(self.pl,text="set object speed",command=self.spee).grid(row=2,column=0) b.bind_widget(self.speed,msg="enter integer from 0 to 10. 0 means no animation.") self.lo=Entry(self.nb) self.lo.grid(row=0,column=1) Label(self.nb,text="Loop length").grid(row=0,column=0) Button(self.nb,text="Start loop",command=self.lop).grid(row=1,column=0) Button(self.nb,text="End loop",command=self.loz).grid(row=2,column=0) Button(self.ia,text="Object"+str(self.index),command=lambda:self.chobj("Object1")).grid(row=0,column=0) self.chs=Button(self.ia,text="Change shape of current object",command=lambda:self.chsh()) self.chs.grid(row=1,column=0) self.addt=Button(self.ia,text="Add object",command=lambda:self.addobj()) self.addt.grid(row=self.jj+1,column=0) self.curob=Label(self.ia,text="current object is Object1") self.curob.grid(row=self.jj+2) self.stf=Button(self.fg,text="Start Creating Function",command=lambda:self.stafunc()) self.stf.grid(row=self.jj1) self.stf1=Button(self.fg,text="Stop Creating Function",command=lambda:self.stofunc()) self.stf1.grid(row=self.jj1+1) func_name="" func="" self.keymenu=Menubutton(self.df,text="keys",relief=RAISED) self.keymenu.grid(row=self.fgh) self.keymenu.menu = Menu(self.keymenu,tearoff=0) self.keymenu["menu"]= self.keymenu.menu keys=['space','enter','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','Up','Down','Left','Right','1','2','3','4','5','6','7','8','9','0','Shift'] for j in keys: self.keymenu.menu.add_command(label=j,command=lambda j=j:self.key(j)) self.fulk=Entry(self.df) self.fulk.grid(row=self.fgh,column=1) self.keylink=Button(self.df,text="add keylink",command=lambda:self.addkeylink()) self.keylink.grid(row=self.fgh,column=2) Button(self.yu,text="Stop animating",command=self.stoani).grid() Button(self.yu,text="Start animating",command=self.staani).grid() Button(self.yu,text="choose bgpic",command=self.bgpic).grid() Button(self.yu,text="choose bgcolour",command=lambda:self.colourchoose("bgcolour")).grid() self.menubar=Menu(self.master) self.file = Menu(self.menubar, tearoff=0) self.file.add_command(label="New",command=lambda:self.new()) self.file.add_command(label="Open",command=lambda:self.ope()) self.file.add_command(label="Save",command=lambda:self.save()) self.file.add_command(label="Exit", command=self.master.quit) self.menubar.add_cascade(label="File", menu=self.file) self.edit = Menu(self.menubar, tearoff=0) self.edit.add_command(label="Undo",command=lambda:self.undo()) self.menubar.add_cascade(label="Edit", menu=self.edit) self.helpa = Menu(self.menubar, tearoff=0) self.helpa.add_command(label="About") self.menubar.add_cascade(label="Help", menu=self.helpa) self.run=Menu(self.menubar,tearoff=0) self.run.add_command(label="Run",command=lambda:self.starun()) self.menubar.add_cascade(label="Run",menu=self.run) self.master.config(menu=self.menubar)
def draw(args, list_long, start_color, end_color): def zoom(event): amount = 0.9 if event.delta < 0 else 1.1 canvas.scale(tk.ALL, 0, 0, amount, amount) def scroll_start(event): canvas.scan_mark(event.x, event.y) def scroll_move(event): canvas.scan_dragto(event.x, event.y, gain=1) to_ommit = [] for val in args.omit: val = bin(int(val, 16)) to_ommit.append(val[2:].zfill(4)) list_bin = [] j = 0 for long in list_long: binary = bin(long)[2:].zfill(8) bin_left = binary[:4] bin_right = binary[4:] if j > args.limit and args.limit != 0: break if bin_left not in to_ommit: list_bin.append(bin_left) j += 1 if j > args.limit and args.limit != 0: break if bin_right not in to_ommit: list_bin.append(bin_right) j += 1 n = len(list_bin) colors = color_range(start_color, end_color, n) root = tk.Tk() root.title(args.file) canvas = tu.ScrolledCanvas(master=root, width=2000, height=2000) canvas.pack(fill=tk.BOTH, expand=tk.YES) screen = tu.TurtleScreen(canvas) screen.screensize(20000, 15000) canvas.bind("<ButtonPress-1>", scroll_start) canvas.bind("<B1-Motion>", scroll_move) canvas.bind('<MouseWheel>', zoom) turtle = tu.RawTurtle(screen) turtle.hideturtle() turtle.speed(10) turtle.pensize(0.0008) turtle.tracer(0, 0) j = 0 for digit in list_bin: u = int(digit, 2) dir = directions[u] turtle.setheading(0) turtle.setheading(dir) turtle.color(colors[j][0], colors[j][1], colors[j][2]) turtle.forward(0.05) j = j + 1 if not args.silent: sys.stdout.write('\033[1;32;1m \rProgress : ' + str(round(float(j) / n * 100, 2)) + "%\033[00m") sys.stdout.flush() if not args.silent: print("\n\n \033[1;91m ---- Computation done ---- \033[00m \n")
bgpanel.image = image1 #Text Area T = Text(frame, bg="white" , height=15, width=116,undo=True) scrollbar = Scrollbar(frame) scrollbar.pack(side=RIGHT, fill=Y) scrollbar.config(command=T.yview) T.config(yscrollcommand=scrollbar.set) T['font'] = ('consolas', '12') T.place(x=500,y=550) T.config(background='black', fg='#67F383') hcanvsize=510 wcanvsize=810 frame2 = tki.Frame(frame, bg='black', width=810, height=510) frame2.place(x=500,y=5) cv = turtle.ScrolledCanvas(frame2, canvwidth=wcanvsize, canvheight=hcanvsize) cv.config(background="black") cv.place(x=0, y=0) screen = turtle.TurtleScreen(cv) screen.bgcolor('black') screen.delay(0) t = turtle.RawTurtle(screen) cv.config(width=800,height=500) cv.pack(side=LEFT,expand=True,fill=BOTH) #ENTRIES #axiom settings axiom=Label(frame, text="Axiom:") axiom.place(x=22, y=20)
self.gone.add((x, y)) if (x, y) in self.pos_turtle.values(): return True elif nth_call > Laby.REACH: return False else: for (i, j) in [(x - Laby.UNIT, y), (x + Laby.UNIT, y), (x, y - Laby.UNIT), (x, y + Laby.UNIT)]: if (i, j) in self.pos_tracker or (i, j) in self.gone or abs( i) >= Laby.RAY or abs(j) >= Laby.RAY: continue if self.parse_area(i, j, nth_call=nth_call + 1): return True return False if __name__ == '__main__': from sys import argv buildfile = None if len(argv) > 1: buildfile = open(argv[1]) if len(argv) > 2: Laby.RAY = int(argv[2]) main_window = tkinter.Tk() canvas = turtle.ScrolledCanvas(main_window) canvas.pack(fill="both", expand=True) Laby.RAY = 100 laby = Laby(canvas, buildfile) ## laby.testme() main_window.mainloop()
#!/usr/bin/env python3 import turtle, tkinter from laby import Laby, Area from sprite import Sprite #preparing the environment... main = tkinter.Tk() can = turtle.ScrolledCanvas(main) can.pack(fill="both", expand=True) screen = turtle.TurtleScreen(can) # we now can make a laby, and put a sprite on it laby = Laby(screen, border=Area((100, 100), (-100, -100))) for loop in laby: pass # politics about player : # we proceed in two halves, this way, if a wall is hit, it will impeach twice the move # This all is to keep a step of one cell (not one half) player = Sprite(screen, step=laby.unit // 2, forbidden=laby.walls) # go to the middle of one cell turtle.RawTurtle.forward(player, player.step) player.left(90) turtle.RawTurtle.forward(player, player.step) # we have to use turtle.RawTurtle.forward to avoid collision checking def move(sprite, heading): """General movement function """ sprite.setheading(heading)
def __init__(self, filename=None): #, root=None): self.root = root = turtle._root = Tk() root.wm_protocol("WM_DELETE_WINDOW", self._destroy) ################# self.mBar = Frame(root, relief=RAISED, borderwidth=2) self.mBar.pack(fill=X) self.ExamplesBtn = self.makeLoadDemoMenu() self.OptionsBtn = self.makeHelpMenu() self.mBar.tk_menuBar(self.ExamplesBtn, self.OptionsBtn) #, QuitBtn) root.title('Python turtle-graphics examples') ################# self.left_frame = left_frame = Frame(root) self.text_frame = text_frame = Frame(left_frame) self.vbar = vbar = Scrollbar(text_frame, name='vbar') self.text = text = Text(text_frame, name='text', padx=5, wrap='none', width=45) vbar['command'] = text.yview vbar.pack(side=LEFT, fill=Y) ##################### self.hbar = hbar = Scrollbar(text_frame, name='hbar', orient=HORIZONTAL) hbar['command'] = text.xview hbar.pack(side=BOTTOM, fill=X) ##################### text['yscrollcommand'] = vbar.set text.config(font=txtfont) text.config(xscrollcommand=hbar.set) text.pack(side=LEFT, fill=Y, expand=1) ##################### self.output_lbl = Label(left_frame, height=1, text=" --- ", bg="#ddf", font=("Arial", 16, 'normal')) self.output_lbl.pack(side=BOTTOM, expand=0, fill=X) ##################### text_frame.pack(side=LEFT, fill=BOTH, expand=0) left_frame.pack(side=LEFT, fill=BOTH, expand=0) self.graph_frame = g_frame = Frame(root) turtle._Screen._root = g_frame turtle._Screen._canvas = turtle.ScrolledCanvas(g_frame, 800, 600, 1000, 800) #xturtle.Screen._canvas.pack(expand=1, fill="both") self.screen = _s_ = turtle.Screen() ##### turtle.TurtleScreen.__init__(_s_, _s_._canvas) ##### self.scanvas = _s_._canvas #xturtle.RawTurtle.canvases = [self.scanvas] turtle.RawTurtle.screens = [_s_] self.scanvas.pack(side=TOP, fill=BOTH, expand=1) self.btn_frame = btn_frame = Frame(g_frame, height=100) self.start_btn = Button(btn_frame, text=" START ", font=btnfont, fg="white", disabledforeground="#fed", command=self.startDemo) self.start_btn.pack(side=LEFT, fill=X, expand=1) self.stop_btn = Button(btn_frame, text=" STOP ", font=btnfont, fg="white", disabledforeground="#fed", command=self.stopIt) self.stop_btn.pack(side=LEFT, fill=X, expand=1) self.clear_btn = Button(btn_frame, text=" CLEAR ", font=btnfont, fg="white", disabledforeground="#fed", command=self.clearCanvas) self.clear_btn.pack(side=LEFT, fill=X, expand=1) self.btn_frame.pack(side=TOP, fill=BOTH, expand=0) self.graph_frame.pack(side=TOP, fill=BOTH, expand=1) Percolator(text).insertfilter(ColorDelegator()) self.dirty = False self.exitflag = False if filename: self.loadfile(filename) self.configGUI(NORMAL, DISABLED, DISABLED, DISABLED, "Choose example from menu", "black") self.state = STARTUP
def __init__(self, filename=None): #, root=None): self.root = root = turtle._root = Tk() root.wm_protocol("WM_DELETE_WINDOW", self._destroy) root.resizable(width=FALSE, height=FALSE) ################# self.mBar = Frame(root, relief=RAISED, borderwidth=2) self.mBar.pack(fill=X) root.title('PonyGE GUI') ################# self.left_frame = left_frame = Frame(root) self.text_frame = text_frame = Frame(left_frame) self.vbar = vbar = Scrollbar(text_frame, name='vbar') self.text = text = Text(text_frame, name='text', padx=5, wrap='none', width=45) vbar['command'] = text.yview vbar.pack(side=LEFT, fill=Y) ##################### self.hbar = hbar = Scrollbar(text_frame, name='hbar', orient=HORIZONTAL) hbar['command'] = text.xview hbar.pack(side=BOTTOM, fill=X) ##################### text['yscrollcommand'] = vbar.set text.config(font=txtfont) text.config(xscrollcommand=hbar.set) text.pack(side=LEFT, fill=Y, expand=1) ##################### self.output_lbl = Label(left_frame, height=1, text=" --- ", bg="#ddf", font=("Arial", 16, 'normal')) self.output_lbl.pack(side=BOTTOM, expand=0, fill=X) ##################### text_frame.pack(side=LEFT, fill=BOTH, expand=0) left_frame.pack(side=LEFT, fill=BOTH, expand=0) self.graph_frame = g_frame = Frame(root) turtle._Screen._root = g_frame turtle._Screen._canvas = turtle.ScrolledCanvas(g_frame, 700, 700, 700, 700) #xturtle.Screen._canvas.pack(expand=1, fill="both") self.screen = _s_ = turtle.Screen() ##### turtle.TurtleScreen.__init__(_s_, _s_._canvas) ##### self.scanvas = _s_._canvas #xturtle.RawTurtle.canvases = [self.scanvas] turtle.RawTurtle.screens = [_s_] turtle.ht() self.scanvas.pack(side=TOP, fill=BOTH, expand=1) self.btn_frame = btn_frame = Frame(g_frame, height=100) self.next_btn = Button(btn_frame, text=" NEXT ", font=btnfont, fg="white", disabledforeground="#fed", command=self.nextGeneration) self.next_btn.pack(side=LEFT, fill=X, expand=1) self.save_btn = Button(btn_frame, text=" SAVE ", font=btnfont, fg="white", disabledforeground="#fed", command=self.savecb) self.save_btn.pack(side=LEFT, fill=X, expand=1) self.redisplay_btn = Button(btn_frame, text=" REDISPLAY ", font=btnfont, fg="white", disabledforeground="#fed", command=self.redisplaycb) self.redisplay_btn.pack(side=LEFT, fill=X, expand=1) self.stop_btn = Button(btn_frame, text=" STOP ", font=btnfont, fg="white", disabledforeground="#fed", command=self.stopIt) self.stop_btn.pack(side=LEFT, fill=X, expand=1) self.btn_frame.pack(side=TOP, fill=BOTH, expand=0) self.graph_frame.pack(side=TOP, fill=BOTH, expand=1) # Grid size, giving population self.n = 3 self.m = 3 # Set up PonyGE self.ge = GE(GRAMMAR_FILE) self.fitness = [0.0 for i in range(self.n) for j in range(self.m)] Percolator(text).insertfilter(ColorDelegator()) self.dirty = False self.exitflag = False self.configGUI(NORMAL, DISABLED, DISABLED, DISABLED, DISABLED, DISABLED, INSTRUCTIONS) # bring the window to front root.attributes('-topmost', 1) root.attributes('-topmost', 0) # none of these succeeds in bringing to front # root.lift() # root.tkraise() # none of these succeeds in focussing # root.focus() # root.focus_force() # self.next_btn.focus_force() self.state = STARTUP self.nextGeneration()