Tkinter输入框数据格式

时间:2019-07-19 09:40:35

标签: python user-interface tkinter serial-port usb

在tkinter(Python GUI)输入框(在RPi上)上获取一组变量,以便ping IP地址,检查USB设备的存在(带有VID和PID)并检查com端口。 但是,当GUI接收数据时,该函数会运行,但是从条目中获取的变量将无法正确执行。

我尝试将ip地址的输入转换为字符串,将vid和pid转换为int,这与com端口条目相同。但是代码仍然无法运行。

用于ping IP和检查USB设备的脚本(不是完整的代码):

response = os.system("ping -c 1 " + self.ip_address)

ping ip并根据响应返回答案

dev = usb.core.find(idVendor=self.vid, idProduct= self.pid)

检查USB并根据响应返回答案

tkinter设置:

entry_IP = Entry(second_frame, bg="white")
entry_IP.grid(row=4,column=1,padx=0,pady=5)
str_IP=entry_IP.get()

主代码:

RM=classname(str_IP,int_VID,int_PID)
RM.check_IP()
RM.check_USB()

我希望代码能够运行或不运行,但是它总是告诉我设备不存在。 当我没有tkinter条目单独运行该功能时,它就很好了!

1 个答案:

答案 0 :(得分:0)

定义str_IP时,该条目不包含任何内容,因此它将等于一个空字符串。您应该通过传递RM=class name(entry.get(),...)

直接检索IP