简体   繁体   English

Python Turtle模块:使用onclick()使turtle消失

[英]Python Turtle module: Using onclick() to make turtle disappear

I can't seem to figure out a way to make turtle disappear on 我似乎无法找出使乌龟消失的方法

This is the area where I need to fix 这是我需要修复的地方

def onclick1():
    isClicked == True


def game():
    turtle.setup(2000,1080)
    wn = turtle.Screen()
    wn.title("Commands")
    Jimmy=turtle.Turtle()
    Jimmy.shape("circle")
    Jimmy.penup()
    numOfCircles = 0
    Jimmy.hideturtle()
    while numOfCircles < 20:
        xPos = uniform(-400,400)
        yPos = uniform(-400,400)
        #Jimmy.setpos(xPos, yPos)
        for i in range(1,5):
            Jimmy.onclick(onclick1())
            Jimmy.shapesize(i+3,i+5)
            Jimmy.showturtle()
            if(isClicked == True):
                Jimmy.hideturtle()
            time.sleep(.3)
        Jimmy.hideturtle()
        numOfCircles = numOfCircles + 1
import turtle
import time
import random
from random import uniform
import math
import tkinter
from tkinter import *



def close_window():
    window.destroy()



def onclick1():
    isClicked == True


def game():
    turtle.setup(2000,1080)
    wn = turtle.Screen()
    wn.title("Commands")
    Jimmy=turtle.Turtle()
    Jimmy.shape("circle")
    Jimmy.penup()
    numOfCircles = 0
    Jimmy.hideturtle()
    while numOfCircles < 20:
        xPos = uniform(-400,400)
        yPos = uniform(-400,400)
        #Jimmy.setpos(xPos, yPos)
        for i in range(1,5):
            Jimmy.onclick(onclick1())
            Jimmy.shapesize(i+3,i+5)
            Jimmy.showturtle()
            if(isClicked == True):
                Jimmy.hideturtle()
            time.sleep(.3)
        Jimmy.hideturtle()
        numOfCircles = numOfCircles + 1




def increaseSize():
    while turtlesize==(x,y)<=(20,5): 
        size = Jimmy.turtlesize()
        increase = tuple([10 * num for num in size])
        Jimmy.turtlesize(*increase)
        print(turtlesize)










isClicked = False
window = tkinter.Tk()
window.title("hello")
window.geometry("2000x1080")
label1 = tkinter.Label(window,bg = "green", font = "ArialMS 60 ",width=2000,height=100)
label2 = tkinter.Label(window, text = "Aim Booster", bg = "green", font = "ArialMS 60 ")
open_button = tkinter.Button(window, text = "Start",font = "Arial 36",width=10,height=1,command=game)
close_button = tkinter.Button(window, text = "EXIT",font = "Arial 10",width=5,height=2,command=close_window)

label1.pack()
label2.pack()
label1.place(x = 0, y = -100)

open_button.pack()
open_button.place(x = 650, y=500 )
close_button.pack()
close_button.place(x=10)

window.mainloop()

Thank you 谢谢

It may have something to do with this: 它可能与此有关:

Jimmy.onclick(onclick1())

If you want to attach the handler there, you actually need to pass in the function itself. 如果要在此处附加处理程序,则实际上需要传递函数本身。 By adding the () , you are not passing in a function, but you are just calling it. 通过添加() ,您没有传递函数,而只是在调用它。 What you probably need to do is this: 您可能需要做的是:

Jimmy.onclick(onclick1)

And in your definition for onclick1 , you should assign to the global variable (also, you cannot do assignments with == ; use = ): onclick1的定义中,您应该分配给全局变量(而且,您不能使用==进行分配;请使用= ):

def onclick1():
    global isClicked
    isClicked = True

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM