Tkinter获取值

2024-10-02 22:25:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我不知道为什么我不能得到刻度的值,为什么我得到这个错误信息。有人能帮我吗?在

from tkinter import *
Op = Tk()
def sb():
    print (Voboll1)




Oboll=Label(Op, text='BOLL')
Oboll.grid(row=1,column=0)

Voboll1 = StringVar()

# Création d'un widget Scale
Oboll1= Scale(Op,from_=-0.2,to=0.2,resolution=0.01,orient=HORIZONTAL,\
length=235,width=20,tickinterval=20,variable=Voboll1,command=sb)
Oboll1.grid(row=1,column=1)


Op.mainloop()

错误消息:

TypeError: sb() takes no arguments (1 given)

Tags: fromimporttkinterdefcolumntkgridsb
1条回答
网友
1楼 · 发布于 2024-10-02 22:25:24

根据文件:

Scale widget command option: this procedure will be passed one argument, the new scale value.

src:http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/scale.html

因此,command参数会自动将一个值传递给您调用的过程,在本例中是sb()。但是,您的sb定义采用了no参数,因此会发生冲突和错误。在

因为您似乎希望使用Voboll1值作为刻度,请将Voboll1作为sb过程的参数。在

def sb(Voboll1):
   ...

应该可以清除错误。在

相关问题 更多 >