CD84380973 发表于 2020-4-13 19:52:43

P75讲问题

from tkinter import *

root=Tk()

def callback(event):
    print("点击位置",event_x,event_y)

frame=Frame(root,width=200,height=200)
frame.bind('<Button-1>',callback)
frame.pack()

mainloop()


Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 1883, in __call__
    return self.func(*args)
File "C:\Users\ASUS\Desktop\75-1.py", line 6, in callback
    print("点击位置",event_x,event_y)
NameError: name 'event_x' is not defined

Mike_python小 发表于 2020-4-13 19:59:29


from tkinter import *

root=Tk()

def callback(event):
    print("点击位置",event.x,event.y)

frame=Frame(root,width=200,height=200)
frame.bind('<Button-1>',callback)
frame.pack()

mainloop()



是event.x和event.y 求最佳

Mike_python小 发表于 2020-4-13 20:01:34

我也是学tkinter的

同行
页: [1]
查看完整版本: P75讲问题