当我尝试更改UI中的focus或grid的值时,出现一个错误:预期的整数参数具有功能(或类似的功能,我不记得我在实验室中得到的确切用词)。因此,函数changevalue()无效,因为参数(例如gridlb)的类型为“ function”。为什么它具有类型函数,如何将其更改为整数?
import visa
import ftdiwrapper as ft
import time
import tkinter as tk
root = tk.Tk()
index = 1
h = ft.FT_Open(index)
def init():
ft.FT_Write(h, 0x51)
ft.FT_Write(h, 0x5f)
def controlon():
ft.FT_Write(h, b"\x20\x01")
def changevalue(param, valuelb, valuehb):
ft.FT_Write(h, bytes([0x32, param, valuelb, valuehb]))
init()
controlon()
changevalue(0x00, 0x00, 5\*0) #energy
changevalue(0x01, 0x00, 0xe4) #filament
focuslb0 = 0x00
focushb0 = 0x00
changevalue(0x03, focushb0, focuslb0) #focus
focuslb = focuslb0
focushb = focushb0
gridlb0 = 0x00
gridhb0 = 0x00
changevalue(0x02, gridlb0, gridhb0) # grid
gridlb = gridlb0
gridhb = gridhb0
def gridplus():
global gridlb, gridhb
if gridlb <= 240:
gridlb += 15
elif gridlb == 255:
gridlb = 0
gridhb += 1
#print('Grid: ', gridlb, gridhb)
changevalue(0x02, gridlb, gridhb)
tk.Label(root, text = gridlb).grid(row=1, column=4)
tk.Label(root, text = gridhb).grid(row=1, column=5)
def gridminus():
global gridlb, gridhb
if gridlb >= 15:
gridlb -= 15
elif gridlb == 0:
gridlb = 255
gridhb -= 1
#print('Grid: ', gridlb, gridhb)
changevalue(0x02, gridlb, gridhb)
tk.Label(root, text = gridlb).grid(row=1, column=4)
tk.Label(root, text = gridhb).grid(row=1, column=5)
def focusplus():
global focuslb, focushb
if focuslb <= 240:
focushb += 15
elif focuslb == 255:
focuslb = 0
focushb += 1
#print('Focus: ', focuslb, focushb)
changevalue(0x03, focuslb, focushb)
tk.Label(root, text = focuslb).grid(row=0, column=4)
tk.Label(root, text = focushb).grid(row=0, column=5)
def focusminus():
global focuslb, focushb
if focuslb >= 15:
focuslb -= 15
elif focuslb == 0:
focuslb = 255
focushb -= 1
#print('Focus: ', focuslb, focushb)
changevalue(0x03, focuslb, focushb)
tk.Label(root, text = focuslb).grid(row=0, column=4)
tk.Label(root, text = focushb).grid(row=0, column=5)
def gridhb():
global focuslb, focushb
gridhb = float(G_hb.get())
changevalue(0x03, gridlb, gridhb)
tk.Label(root, text = gridhb).grid(row=1, column=5)
def focushb():
global focuslb, focushb
focushb = float(F_hb.get())
changevalue(0x03, focuslb, focushb)
tk.Label(root, text = focushb).grid(row=0, column=5)
labelF = tk.Label(root, text = "Focus:").grid(row=0, column=0)
Button_Fplus = tk.Button(root, text = "+", command = focusplus)
Button_Fplus.grid(row=0, column=2)
Button_Fminus = tk.Button(root, text = "-", command = focusminus)
Button_Fminus.grid(row=0, column=3)
labelG = tk.Label(root, text = "Grid:")
labelG.grid(row=1, column=0)
Button_Gplus = tk.Button(root, text = "+", command = gridplus)
Button_Gplus.grid(row=1, column=2)
Button_Gminus = tk.Button(root, text = "-", command = gridminus)
Button_Gminus.grid(row=1, column=3)
F_hb = tk.Entry(root)
G_hb = tk.Entry(root)
F_hb.bind('<Return>', focushb)
G_hb.bind('<Return>', gridhb)
F_hb.grid(row=0, column=1)
G_hb.grid(row=1, column=1)
root.mainloop()
问题来源:stackoverflow
它显示在您的代码中,您已经将gridhb用作变量和函数。
请参阅以
def gridhb():
看起来focushb会遇到相同的问题:
def focushb():
重命名这些名称及其引用(例如此处):
F_hb.bind('<Return>', focushb)
G_hb.bind('<Return>', gridhb)
回答来源:stackoverflow
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。