鱼C论坛

 找回密码
 立即注册
查看: 2278|回复: 1

求助:为啥会报错

[复制链接]
发表于 2020-8-26 08:27:46 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. import tkinter as tk
  2. import crcmod.predefined


  3. def get_data():
  4.     try:
  5.         calc()
  6.     except ValueError:
  7.         root1 = tk.Tk()
  8.         root1.title("提示")
  9.         label2 = tk.Label(root1, text="请输入正确的十六进制数据\n例如a->0a")
  10.         label2.pack()
  11.         button3 = tk.Button(root1, text="确定", command=root1.destroy)
  12.         button3.pack()
  13.         return False


  14. def calc():
  15.     arr = entry1.get()
  16.     print("计算输入框内的值得校验和")
  17.     crc8 = crcmod.predefined.Crc('crc-8')
  18.     crc8.update(bytes().fromhex(arr))
  19.     data = hex(crc8.crcValue)
  20.     print(data)
  21.     v.set(data)
  22.     return True


  23. def clean():
  24.     print("清除输入框内及生成的校验和")
  25.     entry1.delete(0, 'end')
  26.     entry2.delete(0, 'end')


  27. root = tk.Tk()
  28. root.title("CRC校验和工具")
  29. root.geometry('550x150')

  30. label1 = tk.Label(root, text="请输入需要校验的数据:").grid(row=0, sticky='w', padx=10, pady=5)

  31. entry1 = tk.Entry(root)
  32. entry1.place(x=10, y=30, width=500, height=35)
  33. entry1.insert(0, "默认文本...")

  34. v = tk.StringVar()
  35. testCMD = root.register(get_data)
  36. entry2 = tk.Entry(root, textvariable=v, validate='all', validatecommand=(testCMD, '%P'))
  37. entry2.place(x=75, y=95,  width=50)

  38. button1 = tk.Button(root, text="计算", command=get_data).place(x=10, y=90)

  39. button2 = tk.Button(root, text="清除", command=clean).place(x=200, y=90)

  40. root.mainloop()
复制代码

为啥计算框内输入内容后,点击计算第一次会报错
报错如下:
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
    return self.func(*args)
TypeError: get_data() takes 0 positional arguments but 1 was given
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-26 08:44:57 | 显示全部楼层
我这里没问题啊

                               
登录/注册后可看大图
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-26 08:02

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表