python-设置泰克示波器标签

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 等,欢迎沟通讨论
部分文档为做项目过程中的源代码,可能没有注释,有疑问欢迎私信沟通

#电子爱好者
#电子专业
#从事硬件自动测试开发

  • 8
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

QQ546475772

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值