import tkinter as tk
import pyvisa as visa
# 定义全局变量
scope = None
# 初始化示波器
rm = visa.ResourceManager()
# scope = rm.open_resource('TCPIP0::172.19.71.22::inst0::INSTR') # 替换为示波器的实际地址
def on_entry1_change(event):
value = entry1.get()
if value:
global scope
rm = visa.ResourceManager()
resource_string = f"TCPIP0::{value}::inst0::INSTR"
scope = rm.open_resource(resource_string)
# lianjie=f"TCPIP0::{value}::inst0::INSTR"
# print("向示波器发送命令:", lianjie)
# scope = rm.open_resource(lianjie)
def on_entry2_change(event):
value = entry2.get()
if value:
command = ':CH1:LAB "{}";'.format(value)
scope.write(command)
print("向示波器发送命令:", command)
def on_entry3_change(event):
value = entry3.get()
if value:
command = ':CH2:LAB "{}";'.format(value)
scope.write(command)
print("向示波器发送命令:", command)
def on_entry4_change(event):
value = entry4.get()
if value:
command = ':CH3:LAB "{}";'.format(value)
scope.write(command)
print("向示波器发送命令:", command)
def on_entry5_change(event):
value = entry5.get()
if value:
command = ':CH4:LAB "{}";'.format(value)
scope.write(command)
print("向示波器发送命令:", command)
window = tk.Tk()
window.title("示波器标签设置")
# 设置窗口的大小为宽度400像素,高度300像素
# 设置窗口大小
window_width = 300
window_height = 175
# 禁止调整窗口大小
window.resizable(False, False)
# 将窗口显示在屏幕中间
screen_width = window.winfo_screenwidth()
screen_height = window.winfo_screenheight()
x = (screen_width - window_width) // 2
y = (screen_height - window_height) // 2
window.geometry(f"{window_width}x{window_height}+{x}+{y}")
# 第一行:示波器地址文本框
label1 = tk.Label(window, text="示波器地址", anchor="w")
# 设置像素位置和大小
label1.place(x=25, y=0, width=100, height=25)
entry1 = tk.Entry(window)
entry1.place(x=25, y=25, width=250, height=25)
entry1.bind("<KeyRelease>", on_entry1_change)
# 四个标签
label2 = tk.Label(window, text="CH1")
label2.place(x=25, y=50, width=100, height=25)
label3 = tk.Label(window, text="CH2")
label3.place(x=175, y=50, width=100, height=25)
label4 = tk.Label(window, text="CH3")
label4.place(x=25, y=100, width=100, height=25)
label5 = tk.Label(window, text="CH4")
label5.place(x=175, y=100, width=100, height=25)
# 第三行:四个文本框
entry2 = tk.Entry(window)
entry2.place(x=25, y=75, width=100, height=25)
entry2.bind("<KeyRelease>", on_entry2_change)
entry3 = tk.Entry(window)
entry3.place(x=175, y=75, width=100, height=25)
entry3.bind("<KeyRelease>", on_entry3_change)
entry4 = tk.Entry(window)
entry4.place(x=25, y=125, width=100, height=25)
entry4.bind("<KeyRelease>", on_entry4_change)
entry5 = tk.Entry(window)
entry5.place(x=175, y=125, width=100, height=25)
entry5.bind("<KeyRelease>", on_entry5_change)
window.mainloop()
熟悉Labview、Python、VBA、C、Excel公式、PCB Layout、PIC单片机、Visual Studio(ASP.NET)、SQL Server 等,欢迎沟通讨论
部分文档为做项目过程中的源代码,可能没有注释,有疑问欢迎私信沟通#电子爱好者
#电子专业
#从事硬件自动测试开发