开发者社区> 问答> 正文

GUI控制电子束的焦点和栅格

当我尝试更改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

展开
收起
is大龙 2020-03-24 10:06:50 448 0
1 条回答
写回答
取消 提交回答
  • 它显示在您的代码中,您已经将gridhb用作变量和函数。

    请参阅以

    def gridhb():
    

    看起来focushb会遇到相同的问题:

    def focushb():
    

    重命名这些名称及其引用(例如此处):

    F_hb.bind('<Return>', focushb)
    G_hb.bind('<Return>', gridhb)
    

    回答来源:stackoverflow

    2020-03-24 10:06:58
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
复杂环境下的视觉同时定位与地图构建 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载