我有一個秤,它調用一個函數來獲取秤編號。我希望在該功能中包含更多內容,并且我希望它們不僅在我移動比例時發生,而且在我選擇復選按鈕時也發生。問題是比例尺將變量發送到函數(比例尺的位置),而復選按鈕則不會,所以如果我使用復選按鈕的命令調用相同的函數,我會收到錯誤。有人知道是否可以使用比例和復選按鈕調用相同的函數嗎?from tkinter import *root = Tk()def get_scale(scale_value): print(scale_test.get())scale_test = Scale(root, from_=0, to = 10, command = get_scale)button_test = Checkbutton(root)scale_test.pack()button_test.pack()root.mainloop()
1 回答

烙印99
TA貢獻1829條經驗 獲得超13個贊
它有效:
from tkinter import *
root = Tk()
def get_scale(scale_value = 1):
print(scale_test.get())
scale_test = Scale(root, from_=0, to = 10, command = get_scale)
button_test = Checkbutton(root,command = get_scale)
scale_test.pack()
button_test.pack()
root.mainloop()
添加回答
舉報
0/150
提交
取消