0
我有一個使用Python的龜模塊在畫布上一個項目,我想綁定一個<Return>
關鍵是執行自定義命令,我做了一個功能。這是一個例子:Tkinter的:問題與綁定功能
from tkinter import *
import turtle
root = Tk()
mainframe=Frame(root)
mainframe.pack(fill=BOTH)
screen = turtle.ScrolledCanvas(mainframe)
tt = turtle.RawTurtle(screen)
def scrollStart(event): #these functions are for scrolling the widget
screen.scan_mark(event.x, event.y)
def scrollDrag(event):
screen.scan_dragto(event.x, event.y, gain = 1)
text = Text(root)
text.pack()
def executeCommand(): #Problem here
def moveForward(pixels):
tt.forward(pixels)
root.bind("<Return>",executeCommand)
root.mainloop()
但是當我運行它,並擊中moveForward(15)
,它說:
TypeError: executeCommand() takes 0 positional arguments but 1 was given
非常感謝你!忘記所有關於事件的事情 –