是否可以使用 Python 3.x 在 tkinter 中使用 Scale

我有一个秤,它调用一个函数来获取秤编号。我希望在该功能中包含更多内容,并且我希望它们不仅在我移动比例时发生,而且在我选择复选按钮时也发生。问题是比例尺将变量发送到函数(比例尺的位置),而复选按钮则不会,所以如果我使用复选按钮的命令调用相同的函数,我会收到错误。有人知道是否可以使用比例和复选按钮调用相同的函数吗?


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()


蝴蝶刀刀
浏览 116回答 1
1回答

烙印99

它有效: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()
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python