是否可以使用 Tkinter 输入作为输入,通过按钮触发器将值传递给信号发生器?

Is it possible to use Tkinter entry as input, with a button trigger, to pass values to a Signal Generator?

所以我基本上想将不同的值传递给我的 Signal Generator,而不是在我的代码中使用默认的 Frequency/Amplitude 值。

我尝试了 Entry 小部件的 get 方法,但没有成功:

我认为它应该是这样的:

inst.write(f"SOUR:POW:LEV:IMM:AMPL {ampl_input.get()}")

但既然它 returns 文本是字符串,那么我应该以某种方式将该字符串传递给按钮。

import visa
import tkinter as tk


rm = visa.ResourceManager()
print(rm.list_resources())
inst = rm.open_resource('TCPIP::192.168.100.200::INSTR')

ampl = str(-20)
freq_input = str(input())



inst.write("OUTP ON")

def freqset_smb100a():
    inst.write(f""SOUR:FREQ:CW "+ {freq_input.get()})

def amplset_smb100a():
    inst.write("SOUR:POW:LEV:IMM:AMPL " + ampl) #TheSOUR:FREQ etc are commands for the instrument.



HEIGHT = 400
WIDTH = 600

root = tk.Tk()

canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH)
canvas.pack()

frame = tk.Frame(root, bg='#80c1ff', bd=5)
frame.place(relx=0.5, rely=0.1, relwidth=0.75, relheight=0.1, anchor='n')

button = tk.Button(frame, text="Set Freq", font=40, command=freqset_smb100a)
button.place(relx=0.7, relheight=1, relwidth=0.3)

button = tk.Button(frame, text="Set Ampl", font=40, command=amplset_smb100a)
button.place(relx=0.01, relheight=1, relwidth=0.3)

button = tk.Button(frame, text="IDN", font=40, command=show_idn)
button.place(relx=0.35, relheight=1, relwidth=0.3)

entry = tk.Entry(frame, font=15)
entry.place(relx=0.35, relheight=1, relwidth=0.3)

lower_frame = tk.Frame(root, bg='#80c1ff', bd=10)
lower_frame.place(relx=0.5, rely=0.8, relwidth=0.7, relheight=0.2, anchor='n')

label = tk.Label(lower_frame)
label.place(relwidth=1, relheight=1)

root.mainloop()
def freqset_smb100a():
    print(inst.write("SOUR:FREQ:CW 150000000"))
    inst.write(f"SOUR:POW:LEV:IMM:AMPL {ampl_input.get()}")
    print(inst.write("SOUR:POW:LEV:IMM:AMPL -25"))
    print(inst.write("OUTP ON"))

也许是这样的?