主要問題是該函數不會使用正確數量的參數調用。
In Python, you can call a function with parameters in a Tkinter button by using the command attribute of the button. For example, if you have a function named my_func that takes two parameters, you can call it like this: button = tkinter.Button(root, text="Click me", command=lambda: my_func(param1, param2))
在此代碼中,創建了一個按鈕,單擊該按鈕時,將使用參數 param1 和 param2 調用 my_func 函數。
特金特
Tkinter 是 Python 的 GUI 工具包。 它為創建圖形用戶界面提供了一個簡單易用的界面。 Tkinter 可用於創建交互式菜單、對話框和窗口等應用程序。
使用 Tkinter 將參數傳遞給 Button
在 Python 中,您可以使用 pass 關鍵字來調用函數而不提供任何參數。 當您想使用特定參數調用函數但不知道它們是什麼時,這很有用。
要調用帶有特定參數的函數,您可以使用 argv 關鍵字。