xingshong 2022-08-03 23:12 采纳率: 50%
浏览 43
已结题

有哪位能帮我看一下代码?

 from tkinter import HIDDEN,NORMAL,Tk,Canvas
def toggle_eyes():
    current_color=c.itemcget(eye_left,'fill')
    new_color=c.body_color if current_color=='white'else'white'
    current_state=c.itemcget(pupil_left,'state')
    new_state=NORMAL if current_state==HIDDEN else HIDDEN
    c.itemconfigure(pupil_left,state=new_state)
    c.itemconfigure(pupil_right,state=new_state)
    c.itemconfigure(eye_left,fill=new_color)
    c.itemconfigure(eye_right,fill=new_color)
def blink():
    toggle_eyes()
    root.after(250,toggle_eyes)
    root.after(3000,blink)
def show_happy(event):
    if (20<=event.x<=350) and(20<=event.y<=350):
        c.itemconfigure(cheek_left,state=NORMAL)
        c.itemconfigure(cheek_right,state=NORMAL)
        c.itemconfigure(mouth_happy,state=NORMAL)
        c.itemconfigure(mouth_normal,state=HIDDEN)
        c.itemconfigure(mouth_sad,state=HIDDEN)
    return
def hide_happy(event):
    c.itemconfigure(cheek_left,state=HIDDEN)
    c.itemconfigure(cheek_right,state=HIDDEN)
    c.itemconfigure(mouth_happy,state=HIDDEN)
    c.itemconfigure(mouth_normal, state=NORMAL)
    c.itemconfigure(mouth_sad,state=HIDDEN)
root=Tk()
c=Canvas(root,width=400,height=400)
c.configure(bg='dark blue',highlightthickness=0)
c.body_color='SkyBlue1'
body=c.create_oval(35,20,365,350,outline=c.body_color,fill=c.body_color)
ear_left=c.create_polygon(75,80,75,10,165,70,outline=c.body_color,fill=c.body_color)
ear_right=c.create_polygon(255,45,325,10,320,70,outline=c.body_color,fill=c.body_color)
foot_left=c.create_oval(65,320,145,360,outline=c.body_color,fill=c.body_color)
foot_right=c.create_oval(250,320,330,360,outline=c.body_color,fill=c.body_color)
eye_left=c.create_oval(130,110,160,170,outline='black',fill='white')
pupil_left=c.create_oval(140,145,150,155,outline='black',fill='black')
eye_right=c.create_oval(230,110,260,170,outline='black',fill='white')
pupil_right=c.create_oval(240,145,250,155,outline='black',fill='black')
mouth_normal=c.create_line(170,250,200,272,230,250,smooth=1,width=2,state=NORMAL)
mouth_happy=c.create_line(170,250,200,282,230,250,smooth=1,width=2,state=HIDDEN)
mouth_sad=c.create_line(170,250,200,232,230,250,smooth=1,width=2,state=HIDDEN)
cheek_left=c.create_line(70,180,120,230,outline='pink',fill='pink',state=HIDDEN)
cheek_right=c.create_line(280,180,330,230,outline='pink',fill='pink',state=HIDDEN)
c.pack()
c.bind('<Motion>',show_happy)
c.bind('<Leave>',hide_happy)
root.after(1000,blink)
root.mainloop()
File "/Users/fym/Desktop/方嘉铭 编程/屏幕宠物.py", line 16
    if (20<=event.x<=350) and(20<=event.y<=350):
         ^
SyntaxError: invalid decimal literal
  • 写回答

2条回答 默认 最新

  • 亖夕 Python领域新星创作者 2022-08-04 00:53
    关注

    第十六行,小于号要在英文输入法输入,你现在输入的数中文得小于号,改成英文的小于号就好了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 8月13日
  • 已采纳回答 8月5日
  • 创建了问题 8月3日

悬赏问题

  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证