tkinter移动形状

2024-05-16 05:21:20 发布

您现在位置:Python中文网/ 问答频道 /正文

你如何在Python中移动眼睛(当灵魂转向左边时,眼睛仍然在右边)。我试过用c.move(eye,-10,0),当我定义左移动时,我也尝试了为眼睛隐藏状态,并创建了一个状态为normal的左眼,但它不起作用。 谢谢您。在

from tkinter import *
HEIGHT = 500
WIDTH = 800
window = Tk()
window.title('Fetita arunca mingea')
c = Canvas (window, width = WIDTH, height = HEIGHT, bg = 'grey')
c.pack()
school= c.create_rectangle (200, 50,600, 150, fill = 'orange')
school_window1 = c.create_rectangle (250,80, 300, 100, fill= 'yellow')
school_window2 = c.create_rectangle (360,80, 420, 100, fill= 'yellow')
school_window2 = c.create_rectangle (500,80, 550, 100, fill= 'yellow')
body =c.create_polygon (0, 450, 250, 450, 100, 240,fill ='blue')
head = c.create_oval (50, 250, 150, 150, fill = 'ivory')
eye =c.create_oval (120 ,180, 125, 185,fill ='blue')
#eye_left =c.create_oval (75 ,180, 80, 185,fill ='yellow')
eye_left = c.move(eye,-10,0)
mouth = c.create_line (145, 220, 120, 220,fill = 'red')
#mouth_left = c.create_line (55, 220, 80, 220,fill = 'blue')
hand =c.create_line (110, 300, 200, 220, fill = 'black')
GIRL_step = 10
def move_girl(event):
   if event.keysym == 'Up':
        c.move (body, 0, - GIRL_step)
        c.move (head, 0, - GIRL_step)
        c.move (eye, 0, - GIRL_step)
        c.move (mouth, 0, - GIRL_step)
        c.move (hand, 0, - GIRL_step)
    elif event.keysym== 'Down':
        c.move (body, 0, GIRL_step)
        c.move (head, 0, GIRL_step)
        c.move (eye, 0, GIRL_step)
        c.move (mouth, 0, GIRL_step)
        c.move (hand, 0, GIRL_step)
    elif event.keysym== 'Left':
        c.move(eye,-10, 0)
        c.move (body, - GIRL_step, 0)
        c.move (head, - GIRL_step, 0)
        c.move (eye, - GIRL_step, 0)
        c.move (mouth, _GIRL_step, 0)
        c.move (hand, - GIRL_step, 0)
    elif event.keysym== 'Right':
        c.move (body, GIRL_step, 0)
        c.move (head, GIRL_step, 0)
        c.move (eye, GIRL_step, 0)
        c.move (mouth, GIRL_step, 0)
        c.move (hand, GIRL_step, 0)
c.bind_all ('<Key>', move_girl )

Tags: eventmovestepcreatebodyfillheadeye