Jan-24-2019, 04:58 PM
I have 2 parts of code like this
However, when I wrote the codes in Board function and compile it, 2 windows appeared (one is from the turtle and one from the canvas). What did I go wrong?
import tkinter import tkinter.messagebox import turtle import numpy as np from turtle import* turtle.tracer(0,0) wn = turtle.Screen() wn.bgcolor("light blue") wn.title("Turtle") skk = turtle.Turtle() skk.hideturtle() skk.speed(800) skk.pensize(3) def Board2(): for i in range(13): skk.penup() skk.goto(-650,-300+i*50) skk.pendown() skk.forward(1200) skk.penup() for i in range(25): skk.penup() skk.goto(-650+i*50,-300) skk.pendown() skk.left(90) skk.forward(600) skk.right(90) skk.penup() d=0 val=np.zeros((25,13)) def click(x,y): print("trc lam tron") print(x,y) if((x<-675 or x>575) or (y<-325 or y>325)): tkinter.messagebox.showinfo("You fool!!","Wrong position motherfucker!!!") else: if (x%100<=75 and x%100>=25): x=x-x%100+50 else: if(x%100<=25 and x%100>=0): x=x-x%100 else: x=x+100-x%100 if (y%100<=75 and y%100>=25): y=y-y%100+50 else: if(y%100<=25 and y%100>=0): y=y-y%100 else: y=y+100-y%100 print("sau lam tron") print(x,y) global val a=(x+650)//50 b=(y+300)//50 a=int(a) b=int(b) if(val[a][b]==1) or (val[a][b]==2.0): tkinter.messagebox.showinfo("You fool!!","This shit has already taken motherfucker!!!") else: global d if (d%2==0): X(x,y) val[a][b]=1 else: O(x,y) val[a][b]=2 d=d+1 def X(x,y): skk.pensize(8) skk.pencolor("blue") skk.penup() skk.goto(x-12.5,y-12.5) skk.pendown() skk.goto(x+12.5,y+12.5) skk.penup() skk.goto(x-12.5,y+12.5) skk.pendown() skk.goto(x+12.5,y-12.5) skk.penup() def O(x,y): skk.pensize(8) skk.pencolor("red") skk.penup() skk.goto(x,y-12.5) skk.pendown() skk.circle(12.5,360) skk.penup() Board2() onscreenclick(click) turtle.update() turtle.done()And this
import tkinter import turtle import tkinter.messagebox window = tkinter.Tk() canvas = tkinter.Canvas(master = window, width = 800, height = 800) canvas.grid(padx=2, pady=2, row=0, column=0, rowspan=10, columnspan=10) # , sticky='nsew') draw = turtle.RawTurtle(canvas) def Board(a, x, y, size): #draw.pu() draw.penup() draw.goto(x,y) #draw.pd() draw.pendown() for i in range (0, 4): draw.forward(size) draw.right(90) def Board2(): #the whole codes above goes here def Button_click (): tkinter.messagebox.showinfo("Game", "Tic Tac Toe") Play_Button = tkinter.Button(master = window, text ="Play!", command = Button_click) Play_Button.config(bg="cyan",fg="black") Play_Button.grid(padx=2, pady=2, row=0, column=11, sticky='nsew') Board_Button = tkinter.Button(master = window, text ="Draw_Board", command = Board) Board_Button.config(bg="cyan",fg="black") Board_Button.grid(padx=2, pady=2, row=1, column=11, sticky='nsew') window.mainloop()I'm intending to write a function that will display the first part of codes into the function name Board in the above codes.
However, when I wrote the codes in Board function and compile it, 2 windows appeared (one is from the turtle and one from the canvas). What did I go wrong?