Daniel_daodou
稻兜
2019-03-26 10:01
采纳率: 0%
浏览 1.7k

python 里 提示get()方法 缺少了一个参数, 可是get()方法是系统自带的啊,不需要参数啊,求解啊,大神

from tkinter import *
root = Tk()
frame = Frame(root)
frame.pack(padx = 10, pady = 10)
v1 = StringVar
v2 = StringVar
v3 = StringVar

def test(content):
    if content.isdigit():
        return True
    else:
        return False

testCMD = root.register(test)
Entry(frame,textvariable = v1, width = 10, validate = "key",\
      validatecommand = (testCMD,'%P')).grid(row=0,column =0)
Label(frame,text = "+").grid(row = 0, column =1)
Entry(frame,textvariable = v2, width = 10, validate = "key",\
      validatecommand = (testCMD,'%P')).grid(row=0,column =2)
Label(frame,text = "=").grid(row = 0, column =3)
Entry(frame,textvariable = v1, width = 10, validate = "key",\
      validatecommand = (testCMD,'%P')).grid(row=0,column =4)

def calc():
    result = int(v1.get()) + int(v2.get())
    v3.set(result)

Button(frame,text ="jisuanjieguo",command = calc).grid(row=1,column=2,pady=5)

mainloop()

#TODO get(), 为什么会提示少一个参数啊!!!!!!!

报错信息如下:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Ataway\AppData\Local\Programs\Python\Python37-32\lib\tkinter__init__.py", line 1705, in call
return self.func(*args)
File "D:/py/AboutExcel/Tkinter_9_Entry_5_计算器.py", line 26, in calc
result = int(v1.get()) + int(v2.get())
TypeError: get() missing 1 required positional argument: 'self'

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • slevenxulianjie
    slevenxulianjie 2019-03-26 10:12

    你这程序里有两个错误
    第1,应该这么写

    v1 = StringVar()
    v2 = StringVar()
    v3 = StringVar()
    

    v1 = StringVar()这么写表示新建一个变量;
    v1 = Stringvar表示将类型直接赋给v1

    第2,你最后一个输入库应该绑定变量V3,你输成V1了

    点赞 评论
  • enteracity
    json_wuwu 2019-03-27 00:38

    创建对象那里少了括号,我原来也碰到过

    点赞 评论

相关推荐