import tkinter
from tkinter import *
def printword(event):
print("hello")
app = Tk()
textpane = tkinter.Text(app)
textpane.bind('<Control-Key-s>',printword)
textpane.pack()
printword()
app.mainloop()
當我運行代碼時,它給了我型別錯誤
TypeError: printword() missing 1 required positional argument: 'event'
我將如何解決這個問題?
uj5u.com熱心網友回復:
假設您的函式實際上并未使用event其主體中的物件,最簡單的解決方案是使事件引數可選:
def printword(event=None):
print("hello")
這使您可以不帶引數 ( printword()) 呼叫它,同時還允許它接受從 tkinter 的事件處理機制傳入的引數。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/468251.html
