Python 滑块值

Python Slider Value

我的 GUI 中有一个刻度,我正试图从中获取连续值。下面是我的代码。

from Tkinter import *
class Application(Frame):
   def getVoltage(self):
      print self.voltage_scale.get()
   def createWidgets(self):
      self.voltage_scale = Scale(self)
      self.voltage_scale["from_"] = 0
      self.voltage_scale["to"] = 32
      self.voltage_scale["orient"] = "horizontal"
      self.voltage_scale["command"] = self.getVoltage
      self.voltage_scale.grid(column=0,row=9)
   def __init__(self,Master=None)
      Frame.__init__(self,master)
      self.createWidgets()
      self.tn = None
root = Tk()
app = Application(master=root)
app.mainloop()
root.destroy()

当我 运行 上面的代码并开始移动我的滑块时,我收到一条错误消息:

getVoltage() takes exactly 1 argument, two was given

我想要做的就是获取滑块的值。任何帮助将不胜感激。

def getVoltage(self, event_arg): 会解决这个问题。某些 tk 控件的命令将一些事件数据作为额外参数传递