在不破坏我其余代码的情况下中断循环

时间:2019-05-21 16:23:06

标签: python tkinter

我正在对与更多代码集成的python复选框进行编码,我希望能够在不停止其余代码的情况下停止运行复选框代码。这是一个游戏场景,因此在复选框之后,我立即定义了精灵和AI来对抗它。我希望能够停止复选框代码,而不会阻止我定义角色和敌人。

root, root.title("Adventure Game"), text == (">>>>>>>>>>Your adventure role<<<<<<<<<<").grid [row==0, sticky==N]              
print ("Warrior: %d,\nMage: %d,\nBarbarian: %d,\nDragon rider: %d") %(var1.get(), var2.get(), var3.get(), var4.get(), var5.get()

   def var1():
       Checkbutton(root, text="Warrior", variable=var1).grid(row=1, sticky=W)
   def var2():
       Checkbutton(root, text="Mage", variable=var2).grid(row=2, sticky=W)
   def var3():
       Checkbutton(root, text="Barbarian", variable=var3).grid(row=3, sticky=W)
   def var4():
       Checkbutton(root, text="Dragon rider", variable=var4).grid(row=4, sticky=W)
   def var5():
       Checkbutton(root, text="Potion maker", variable=var5).grid(row=5, sticky=W)

   btn=Button.grid(row=6, sticky=W, pady=4)
   btn.pack()
   btn["text"]=QUIT
   def click():
       command=root.destroy
   btn=Button.grid(row=5, sticky=E, pady=4)
   btn.pack()
   btn["text"]=Show
   def click():
       command=var_states

def AI():
    win.listen()
    win.onkeypress(user_character_block, "Up")
    win.onkeypress(user_paddle_down, "Down")
    AI_paddle.forward(AI_paddle.speed)
    y = AI_paddle.ycor()
    if y < -300 or y > 300:
    AI_paddle.speed *= -1
    sqrt((mob.x-player.x)**2 + (mob.y-player.y)**2)

def sprite(x,y):
    gamewindow.blit(img,(x,y))
    x=(800*0.45)
    y=(600*0.8)
    xchange=0
    imgspeed=0
    while running:
        for event in pygame.event.get():
            if event.type==QUIT:
                running=False
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    xchange=-5
                elif event.key==pygame.K_RIGHT:
                    xchange=5
            if event.type==pygame.KEYUP:
                if event.key==pygame.K_LEFT or event.key==pygame.K_RIGHT:
                    xchange=0

0 个答案:

没有答案