def animate(self): turtle_screen = turtle.TurtleScreen(self.canvas) turtle_screen.bgcolor("#2a408c") self.canvas.pack() for i in range(0, self.num_turtles): DEC = star_pos[i][0] RA = star_pos[i][1] * 2.5 pen = turtle.RawTurtle(turtle_screen) self.canvas.pack() pen.hideturtle() pen.speed(int(self.e.get())) pen.pensize(2) pen.up() pen.forward(abs(RA - 2.31) * 16) pen.pendown() pen.left(90) pen.color(random.choice(self.colors)) pen.circle(((self.radius(RA, 2.31, DEC, 89)) * 2), self.extent) self.stars.append(pen) for x in range(0, 4): for i in range(0, self.num_turtles): DEC = star_pos[i][0] RA = star_pos[i][1] * 2.5 self.stars[i].circle(((self.radius(RA, 2.31, DEC, 89)) * 2), self.extent)
def make_gui(cls, interactive=False): gui = cls() root = Tk() gui.root = root f = Frame(root) f.pack(side='top', expand=1, fill='both') gui.frame = f canvas = Canvas(f) canvas.bind("<Configure>", gui.configure_canvas) canvas.pack(side='top', expand=1, fill='both') gui.canvas = canvas screen = turtle.TurtleScreen(canvas) gui.screen = screen if interactive: output = ScrolledText(f, height=10, state='disabled') output.bind("<1>", lambda event: output.focus_set()) output.pack(side='top', expand=0, fill='x') gui.output = output text_input = Frame(f) prompt = Label(text_input, text="?") prompt.pack(side='left', expand=0) gui._prompt_label = prompt input_var = StringVar() gui.input_var = input_var entry = Entry(text_input, textvariable=input_var) entry.bind('<Return>', gui.handle_input) entry.bind('<Up>', gui.back_history) entry.bind('<Down>', gui.forward_history) entry.pack(side='left', expand=1, fill='x') text_input.pack(side='top', expand=0, fill='x') return gui
def __init__(self, master): self.master = master self.master.title("Your Face!") self.canvas = tk.Canvas(master) self.canvas.config(width=600, height=600) self.canvas.pack(side=tk.LEFT) self.screen = turtle.TurtleScreen(self.canvas) self.faceColour = (0,'#FFC0CB') print(type(self.faceColour[1])) self.eyeColour = "blue" self.mouthColour = "red" self.screen.colormode(255) # button tk.Button(self.master, text="Draw Face", command=self.drawFace).pack() # label self.faceColourCombo = ttk.Label(root, text = "Select the Month :", font = ("Times New Roman", 10)) self.faceColourCombo.pack() # Combobox creation n = tk.StringVar() self.monthchoosen = ttk.Combobox(root, width = 27, textvariable = n) self.turtle = turtle.RawTurtle(self.screen, shape="turtle") self.turtle.color("green") tk.Button(self.master, text="Choose face colour", command=self.chooseFaceColour).pack() tk.Button(self.master, text="Choose eye colour", command=self.chooseEyeColour).pack() tk.Button(self.master, text="Choose mouth colour", command=self.chooseMouthColour).pack()
def display_help_window(): from turtle import TK root = TK.Tk() frame = TK.Frame() canvas = TK.Canvas(root, width=300, height=200, bg="white") canvas.pack() help_screen = turtle.TurtleScreen(canvas) help_t = turtle.RawTurtle(help_screen) help_t.penup() help_t.hideturtle() help_t.speed('fastest') width, height = help_screen.screensize() line_height = 20 y = height // 2 - 30 for s in ("Click on cells to make them alive or dead.", "Keyboard commands:", " E)rase the board", " R)andom fill", " S)tep once or", " C)ontinuously -- use 'S' to resume stepping", " Q)uit"): help_t.setpos(-(width / 2), y) help_t.write(s, font=('sans-serif', 14, 'normal')) y -= line_height
def displayStartLine(self, point): point = list(point) theScreen = t.TurtleScreen(self.canvas2) path = t.RawTurtle(theScreen) path.clear() #隐藏画笔 path.hideturtle() #抬起画笔 path.penup() for i in range(len(point)): path.goto(point[i] * 5 - 250, 230) path.write(str(point[i])) path.goto(point[0] * 5 - 250, 230) path.pendown() self.canvas2.create_line(-250, -230, 250, -230, fill="red") x = 10 path.pendown() for i in range(len(point)): # self.canvas.create_line(point[i],x+(i+1)*10,point[i+1],x+(i+2)*10,fill="red") path.goto(point[i] * 5 - 250, 230 - 20 * i) path.penup() path.write(point[i], font=("Arial", 8)) path.pendown() self.textLog.insert( END, '\n********' + str(self.var.get()) + '************') self.textLog.insert(END, '\n访问的磁道序列为:\n' + str(point)) sum_gap = sum([(abs(point[i] - point[i - 1])) for i in range(1, len(point))]) self.textLog.insert(END, '\n移动的磁道数为:' + str(sum_gap)) self.textLog.insert( END, '\n平均移动的磁道数为:' + str(sum_gap / self.Al.TRACK_REQUEST_COUNT)) self.RectangleShow(point)
def __init__(self, *args: Any, game: Hangman, **kwargs: Any) -> None: super().__init__(*args, **kwargs) self.game = game self.visible_word = tkinter.Label(self, relief=tkinter.SUNKEN, bd=2, padx=5, pady=5, font='TkFixedFont') self.visible_word.grid(row=0, column=0, sticky='ns') self.canvas = tkinter.Canvas(self, bd=0, highlightthickness=0) self.canvas.grid(row=1, column=0, sticky='news') self.turtle_screen = turtle.TurtleScreen(self.canvas) self.turtle_screen.bgcolor(self['background']) self.turtle = HangmanTurtle(self.turtle_screen) self.turtle.pensize(2) self.turtle.hideturtle() self.feedback = tkinter.Label(self) self.feedback.grid(row=2, column=0, sticky='news') self.feedback.bind( '<Configure>', lambda _: self.feedback.configure( wraplength=self.feedback.winfo_width())) self.controls = tkinter.Frame(self) self.controls.grid(row=3, column=0, sticky='news') self.update_controls()
def __init__(self, ip: str, port: int): self.client = OSCClient(ip, port) self.root = tkinter.Tk() self.root.geometry("400x400") self.root.protocol("WM_DELETE_WINDOW", self.handleQuit) bind_event_data(self.root, Stub.eventPIGPIO, self.handlePIGPIO) self.canvas = tkinter.Canvas(self.root, width=400, height=400) self.screen = turtle.TurtleScreen(self.canvas) self.screen.tracer(0, 0) self.machine = Machine(pigpio_provider.pi('GUI', self.screen)) self.machine.setup() frame_top = tkinter.Frame(self.root) self.button_ping = tkinter.Button(frame_top, text='ping', command=self.call_ping) self.button_reset = tkinter.Button(frame_top, text='reset', command=self.call_reset) self.button_ping.pack(side='left', anchor='n') self.button_reset.pack(side='left', anchor='n') frame_command = self.__renderFrameCommand() frame_top.pack() frame_command.pack() self.canvas.pack(anchor='s')
def yardým_penceresini_göster(): from turtle import TK # Sýnýf ithali... #kök = TK.Tk() # Metod çaðýrmalý nesne... #çerçeve = TK.Frame() tuval = TK.Canvas (TK.Tk(), width=400, height=200, bg="WHITE") # Yardým ekran büyüklüðü... tuval.pack() yardým_ekraný = turtle.TurtleScreen (tuval) en, boy = yardým_ekraný.screensize() yardým_penceresi = turtle.RawTurtle (yardým_ekraný) yardým_penceresi.penup() yardým_penceresi.hideturtle() yardým_penceresi.speed ('fastest') satýr_boyu = 20 y = boy / 2 - 30 for satýr in ("Fareyle týklanan hücre canlanýr veya ölür.", "Pano odaklýyken klavye komutlarý:", " ", " S)il panoyu tamamen", " G)eliþigüzel pano dolacak", " T)ek tek adýmlarla ilerlenir", " D)evamlý ilerlenir -- T ile tek teke dönebilirsin", " ", " K)apat pencereleri ve çýk"): yardým_penceresi.setpos (- en / 2, y) yardým_penceresi.write (satýr, font = ('sans-serif', 14, 'normal')) y -= satýr_boyu
def __init__(self,xmin,ymin,xmax,ymax,title=None,ltype=None): dx = 0.25*(xmax-xmin) dy = 0.10*(ymax-ymin) self.xmin = xmin self.xmax = xmax self.ymin = ymin self.ymax = ymax self.dx = dx self.dy = dy self.title1 = title self.ltype = ltype self.root = turtle.TK.Tk() if (title==None): self.root.title("xyplotter") else: self.root.title(title) #self.cv1 = turtle.TK.Canvas(self.root,width=750,height=600,bg="#ddffff") self.cv1 = turtle.TK.Canvas(self.root,width=500,height=400,bg="#ddffff") self.cv1.pack() self.s1 = turtle.TurtleScreen(self.cv1) self.s1.setworldcoordinates(xmin-dx,ymin-dy,xmax+dx,ymax+dy) self.t1 = turtle.RawTurtle(self.s1) self.t1.speed("fastest") self.t1.screen.tracer(10000) self.t1.hideturtle() self.t1.pensize(1) self.t1.color("black") _fillsquare(self.t1,self.xmin,self.ymin,self.xmax,self.ymax) _labels(self.t1,self.xmin,self.ymin,self.xmax,self.ymax,self.dx,self.dy,self.ltype) self.s1.update()
def __init__(self,mrow,mcolumn): self.row=mrow self.column=mcolumn self.value="" self.label = tk.LabelFrame(master=Board.master, width=235, height=235,bg="Black") self.mark=1 #grid manager to set label localization self.label.grid(row=mrow, column=mcolumn) #Create button and set it localization. You can change it font without changing size of button, but if You set too big not whole will be visible self.cell=tk.Button(master=Board.master, bg="Black", command=self.turn, state="normal", activebackground="Black", relief="ridge" ) #Use sticky to button took up the whole label area self.cell.grid(row=mrow, column=mcolumn, sticky='nesw') self.sc=tk.Canvas(master=Board.master,width=230,height=230,bd=0,bg="Black") self.nop=tl.TurtleScreen(self.sc)
def __init__(self, root, w=800, h=800, speed=0): super().__init__(root, w, h) self.screen = turtle.TurtleScreen(self.canvas) self.pen = turtle.RawTurtle(self.screen) self.pen.speed(speed) self.pen.hideturtle() self.screen.bgcolor("#fffef2")
def draw(): t.up() t.goto(65,-100) t.clear() t.setheading(random.randint(0, 360)) variables = { "length":end, "sides":sides_, "pensize":pensize_, "r":increment } values = { "length":5, "sides":5} #If a variable is a noninteger, replace it with a random integer for var, entry in variables.items(): try: globals()[var] = int(entry.get()) except ValueError: globals()[var] = random.randint(2, 6) if shape_color.get() == "": t.color(random.choice(COLORS)) else: try: t.color(shape_color.get().lower()) except turtle.TurtleGraphicsError: t.color(random.choice(COLORS)) try: turtle.TurtleScreen(canvas).bgcolor(bg_color.get().lower()) except tk._tkinter.TclError: turtle.TurtleScreen(canvas).bgcolor(random.choice(COLORS)) t.pd() start = time.time() while time.time()-start < length: global r r += 1 t.circle(r, steps=sides) t.left(1)
def mobile(canvas): mobile = turtle.TurtleScreen(canvas) mobile.bgcolor('white') brush = turtle.RawTurtle(mobile) brush.ht() text(brush) # mobile brush.speed(2) brush.up() brush.goto(-100, 100) brush.down() #outer lines brush.fd(130) brush.seth(270) brush.fd(240) brush.seth(180) brush.fd(130) brush.seth(90) brush.fd(240) #GOTO brush.up() brush.goto(-85, 80) brush.down() # inner screen brush.fillcolor('black') brush.begin_fill() brush.seth(0) brush.fd(100) brush.seth(270) brush.fd(180) brush.seth(180) brush.fd(100) brush.seth(90) brush.fd(180) brush.end_fill() #GOTO brush.up() brush.goto(-25, -120) brush.down() #button brush.pensize(2) brush.circle(12) #GOTO brush.up() brush.goto(-50, 90) brush.down() #top line brush.seth(0) brush.fd(30)
def __init__(self, canvas): self.screen = tt.TurtleScreen(canvas) self.screen.screensize( 100, 100) # Screen 大小决定绘图可视区域大小,当Screen 大小超出屏幕区域时,ScrolledCanvas会出现滚动条 self.screen.bgcolor('grey') self.screen.tracer(False) self.turtle = tt.RawTurtle(self.screen) self.turtle.ht()
def __init__(self, canvas): self.screen = tt.TurtleScreen(canvas) #self.screen.screensize(100, 100) # Screen 大小决定绘图可视区域大小,当Screen 大小超出屏幕区域时,ScrolledCanvas会出现滚动条 self.screen.bgcolor('black') self.screen.tracer(True) self.turtle = tt.RawTurtle(self.screen) self.turtle.speed(0) self.turtle.ht() self.turtle.color('white')
def newwindow(title=None, size=(200, 200), pos=(100, 100)): wn = TK.Tk() wn.geometry(sizetostr(size, pos)) if title == None: title = rander() wn.title(title) cv = TK.Canvas(wn, width=size[0], height=size[1]) cv.pack() sc = turtle.TurtleScreen(cv) return (wn, cv, sc)
def hand(canvas): hand = turtle.TurtleScreen(canvas) hand.bgcolor('white') brush = turtle.RawTurtle(hand) brush.ht() text(brush) brush.up() brush.goto(-40,-70) brush.down() brush.speed(2) brush.fillcolor('PapayaWhip') brush.begin_fill() # left side wrist brush.seth(100) brush.fd(50) #thumb brush.seth(120) brush.fd(100) brush.circle(-10,180) brush.seth(305) brush.fd(50) #index brush.setheading(93) brush.fd(100) brush.circle(-10,180) brush.setheading(272) brush.fd(80) #middle finger brush.setheading(88) brush.fd(110) brush.circle(-10,180) brush.setheading(272) brush.fd(100) #ring finger brush.setheading(88) brush.fd(80) brush.circle(-10,180) brush.setheading(270) brush.fd(80) #pinky finger brush.setheading(88) brush.fd(60) brush.circle(-8,180) brush.setheading(268) brush.fd(200) brush.end_fill()
def setupTurtle(canvas): screen = turtle.TurtleScreen(canvas) t = turtle.RawTurtle(screen) screen.tracer(100, 0) t.hideturtle() t.speed(0) t.home() t.pd() return t, screen
def __init__(self, canvas=None): # Game stuff self.player_list = [] # holds the player list self.paused = True # paused flag self.game_over_limit = None # allows single and muli player modes self.play_again = None # flag that enables the y/n selection at end of round # Gui stuff self.screen = turtle.TurtleScreen( cv=canvas) if canvas else turtle.Screen() self.screen.tracer(False) self.screen.onkey(self.toggle_pause, 'space')
def __init__(self, master=None): super().__init__(master) self.master = master self.pack() self.canvas = Canvas(self) # 画板 self.pen = turtle.RawTurtle(turtle.TurtleScreen( self.canvas)) # 海龟画图的画笔,绑定画板 self.pen.up() self.pen.goto(23, -23) self.canvas.config(scrollregion=(0, 0, 1396, 600), width=1396, height=600) self.canvas.grid(row=0, column=0, columnspan=14) Point.canvas = self.canvas print(self.canvas.cget("width")) self.buttongroup = self.create_buttongroup() # 生成所有按钮 self.mouse_click_pos = (23, 23) self.canvas.create_oval(20, 20, 26, 26, fill="black", tags="mouseclick") # 画板点击事件 self.canvas.bind("<Button-1>", self.mouse_click) self.canvas.create_text(self.mouse_click_pos[0] + 1, self.mouse_click_pos[1] - 9, text="Now", font=("Pursia", 10), tags="now") self.point_name = StringVar() self.point_name_input = Entry(self, bd=2, textvariable=self.point_name) self.point_name_input.grid(row=1, column=1, sticky=E, padx=8) self.point_set = set() self.points = [] # 点集 self.point_map = {} # 序号到点的映射 self.point_name_set = [] self.p1 = StringVar() self.p2 = StringVar() self.line_p1 = ttk.Combobox(self, textvariable=self.p1) self.line_p2 = ttk.Combobox(self, textvariable=self.p2) self.line_p1.grid(row=1, column=3, sticky=W) self.line_p2.grid(row=2, column=3, sticky=W) self.start = StringVar() self.start_pos = ttk.Combobox(self, textvariable=self.start) self.start_pos.grid(row=2, column=0, sticky=E, padx=8) self.end = StringVar() self.end_pos = ttk.Combobox(self, textvariable=self.end) self.end_pos.grid(row=3, column=0, sticky=E, padx=8) self.traffic_light = []
def __init__(self, canvas): self.screen = tt.TurtleScreen(canvas) self.screen.bgcolor('black') self.screen.tracer(True) self.turtle = tt.RawTurtle(self.screen) self.turtle.speed(0) self.turtle.ht() self.turtle.color('white') self.turtle.up() self.turtle.goto(1100, -350) self.turtle.seth(0)
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 __init__(self): self.screen = tk.Tk() self.screen.title("3D Graphic") self.screen.geometry("500x600") self.screen.resizable(False,False) self.__buf1 = tk.Canvas(master = self.screen, width=500,height=500) self.__buf2 = tk.Canvas(master = self.screen, width=500,height=500) self.__buffer1 = t.TurtleScreen(self.__buf1) self.__buffer2 = t.TurtleScreen(self.__buf2) self.__buf2.pack_forget() self.__buf1.pack() self.__current = 1 self.__t1 = t.RawTurtle(self.__buffer1) self.__t2 = t.RawTurtle(self.__buffer2) self.__t1.speed(0) self.__t2.speed(0) self.__t1.hideturtle() self.__t2.hideturtle() self.__t2.color("blue") self.__t1.penup() self.__t1.penup()
def initTurtle(self): self.screen = turtle.TurtleScreen(self.canvas) self.screen.bgcolor('black') self.screen.screensize(self.canvasWidth, self.canvasHeight) self.pen = turtle.RawTurtle(self.screen) self.pen.tracer(False) self.pen.hideturtle() self.pen.color('white') self.pen.penup() self.pen.setpos(-self.canvasWidth / 2, -self.canvasHeight / 2) self.pen.setheading(45) self.pen.pendown()
def __init__(self, master): super().__init__(master=master) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self.canvas = tk.Canvas(self, height=CANVAS_HEIGHT, width=CANVAS_WIDTH) self.canvas.grid(row=0, column=0, sticky="NESW") self.t_screen = turtle.TurtleScreen(self.canvas) self.t_screen.delay(0) self.line_t = turtle.RawTurtle(self.t_screen) self.line_t.setpos(100, 100) self.scale_t = turtle.RawTurtle(self.t_screen) ## self.scale_t.pu() self.draw_all()
def change_dropdown(self, *args): option = self.option.get() if option == 'Simulation Screen': print(option) if self.simulation_screen == None: self.simulation_screen = tk.Frame(self._master, width=685, height=535) self.simulation_screen.place(x=300, y=50) self.turtle_display = tk.Canvas(self._master, width=670, height=520, background='white') self.turtle_display.pack() self.turtle_screen = turtle.TurtleScreen(self.turtle_display) self.screen_edit_button = tk.Button(self._master, text="Edit", command=self.edit_screen) self.screen_edit_button.place(x=300, y=570) self.screen_delete_button = tk.Button(self._master, text="Delete", command=self.delete_screen) self.screen_delete_button.place(x=350, y=570)
def adapter(): # aloue la taille dispo a la tortue R.xFen = calc.winfo_width() - f_clavier.winfo_width() - 30 R.yFen = calc.winfo_height() - l_mode.winfo_height() - 30 R.actualiser() fenTortue.destroy() global fenTortue global ecran global t fenTortue = turtle.Canvas(f_turtle, height=R.yFen, width=R.xFen) fenTortue.pack(padx=10, pady=10) ecran = turtle.TurtleScreen(fenTortue) t = turtle.RawTurtle(ecran) R.actualiser() t.ht()
def newScreen(): """ complicated function that allows us to have mutiple turtle screens """ root = tkinter.Tk() canvas = tkinter.Canvas(root, width=800, height=800) canvas.pack() sc = turtle.TurtleScreen(canvas) def bye(e): root.destroy() def exitonclick(): canvas.bind("<Button-1>", bye) root.mainloop() sc.exitonclick = exitonclick return sc
def __init__(self): self.root=tk.Tk() self.root.geometry("1920x1080") self.root.title("Rifat's Tic Tac Toe") self.root["bg"]="black" self.root.resizable(0,0) self.root.iconbitmap("tictactoe.ico") self.root.state("zoomed") self.f=tk.Frame(self.root) self.f.pack() self.c=tk.Canvas(self.f,height=1080,width=1920,bg="Blue") self.sc=tl.TurtleScreen(self.c) self.c.pack() self.tt=tl.RawTurtle(self.sc) self.sc.bgcolor("Black")
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()