【问题标题】:Problems With Tkinter in python 2.5python 2.5中Tkinter的问题
【发布时间】:2013-06-19 03:18:00
【问题描述】:

所以我正在做一个简单的程序,基本上在屏幕上制作一个比例/滑动条。当我运行应用程序时,比例会显示并工作,但它不会将值打印到控制台(终端)。相反,它会打印错误消息

import Tkinter
class App:
    def __init__(self,parent):
        self.scale = Tkinter.Scale(parent,from_ = 0, to = 100, command = self.getVal)
        self.scale.pack()
    def getVal(self):
        amount = self.scale.get()
        print str(amount)
root = Tkinter.Tk()

app = App(root)
root.mainloop()

这是错误信息:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tkinter.py", line 1403, in __call__
    return self.func(*args)
TypeError: getVal() takes exactly 1 argument (2 given)

我是 Tkinter 的新手,所以我有点迷茫。

编辑:Python 2.5 的家伙。对不起。

【问题讨论】:

    标签: python tkinter python-2.5


    【解决方案1】:

    command 回调接收一个新的比例值作为参数。将getVal 定义更改为:

    def getVal(self, newscale):
        print newscale
    

    【讨论】:

      猜你喜欢
      • 2014-09-20
      • 1970-01-01
      • 2020-09-18
      • 1970-01-01
      • 2016-05-25
      • 2018-05-17
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      相关资源
      最近更新 更多