2

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

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

我认为它应该是这样的:

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

但由于它将文本作为字符串返回,所以我应该以某种方式将该字符串传递给按钮。

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()
4

1 回答 1

2
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"))

也许是这样的?

于 2019-09-25T08:01:20.913 回答