| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
- import tkinter as tk
 
 - import crcmod.predefined
 
  
 
- def get_data():
 
 -     try:
 
 -         calc()
 
 -     except ValueError:
 
 -         root1 = tk.Tk()
 
 -         root1.title("提示")
 
 -         label2 = tk.Label(root1, text="请输入正确的十六进制数据\n例如a->0a")
 
 -         label2.pack()
 
 -         button3 = tk.Button(root1, text="确定", command=root1.destroy)
 
 -         button3.pack()
 
 -         return False
 
  
 
- def calc():
 
 -     arr = entry1.get()
 
 -     print("计算输入框内的值得校验和")
 
 -     crc8 = crcmod.predefined.Crc('crc-8')
 
 -     crc8.update(bytes().fromhex(arr))
 
 -     data = hex(crc8.crcValue)
 
 -     print(data)
 
 -     v.set(data)
 
 -     return True
 
  
 
- def clean():
 
 -     print("清除输入框内及生成的校验和")
 
 -     entry1.delete(0, 'end')
 
 -     entry2.delete(0, 'end')
 
  
 
- root = tk.Tk()
 
 - root.title("CRC校验和工具")
 
 - root.geometry('550x150')
 
  
- label1 = tk.Label(root, text="请输入需要校验的数据:").grid(row=0, sticky='w', padx=10, pady=5)
 
  
- entry1 = tk.Entry(root)
 
 - entry1.place(x=10, y=30, width=500, height=35)
 
 - entry1.insert(0, "默认文本...")
 
  
- v = tk.StringVar()
 
 - testCMD = root.register(get_data)
 
 - entry2 = tk.Entry(root, textvariable=v, validate='all', validatecommand=(testCMD, '%P'))
 
 - entry2.place(x=75, y=95,  width=50)
 
  
- button1 = tk.Button(root, text="计算", command=get_data).place(x=10, y=90)
 
  
- button2 = tk.Button(root, text="清除", command=clean).place(x=200, y=90)
 
  
- 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 |   
 
 
 
 |