[英]Controlling IP Cameras with Tkinter Buttons (Python)
I have been trying to create a GUI with tkinter to control 4 IP cameras with Python.我一直在尝试使用 tkinter 创建一个 GUI,以使用 Python 控制 4 个 IP 相机。 At first I thought it's because I didn't have the right IP or Ports but I used packet sender to check it out.
起初我以为是因为我没有正确的 IP 或端口,但我使用了数据包发送器来检查它。 I'm confused on why the program won't work when I try to use it in Python 2.7.
当我尝试在 Python 2.7 中使用该程序时,我对为什么该程序不起作用感到困惑。 Below is the code for one of my cameras - left camera, it is a PTZoptics camera.
下面是我的一台摄像机的代码 - 左摄像机,它是一台 PTZoptics 摄像机。 The camera and the computers are all connected on one network via ethernet.
相机和计算机都通过以太网连接在一个网络上。 Currently, I am currently controlling them with an IP joystick.
目前,我正在使用 IP 操纵杆控制它们。
import socket
import tkinter as tk
class Example(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
self.up = tk.Button(self, text="LEFT CAMERA UP")
self.down = tk.Button(self, text="LEFT CAMERA DOWN")
self.left = tk.Button(self, text="LEFT CAMERA LEFT")
self.right = tk.Button(self, text="LEFT CAMERA RIGHT")
self.up.pack(side="top")
self.down.pack(side="bottom")
self.left.pack(side="left")
self.right.pack(side="right")
self.up.bind("<ButtonPress>", self.on_LCup)
self.up.bind("<ButtonRelease>", self.on_LCrelease)
self.down.bind("<ButtonPress>", self.on_LCdown)
self.down.bind("<ButtonRelease>", self.on_LCrelease)
self.left.bind("<ButtonPress>", self.on_LCleft)
self.left.bind("<ButtonRelease>", self.on_LCrelease)
self.right.bind("<ButtonPress>", self.on_LCright)
self.right.bind("<ButtonRelease>", self.on_LCrelease)
def on_LCup(self, event):
LeftHost = '10.30.1.41'
port1 = 5678
LC = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
LC.connect((LeftHost, port1))
LC.send("81 01 06 01 08 08 03 01 FF")
def on_LCdown(self, event):
LeftHost = '10.30.1.41'
port1 = 5678
LC = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
LC.connect((LeftHost, port1))
LC.send("81 01 06 01 08 08 03 02 FF")
def on_LCleft(self, event):
LeftHost = '10.30.1.41'
port1 = 5678
LC = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
LC.connect((LeftHost, port1))
LC.send("81 01 06 01 08 08 01 03 FF")
def on_LCright(self, event):
LeftHost = '10.30.1.41'
port1 = 5678
LC = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
LC.connect((LeftHost, port1))
LC.send("81 01 06 01 08 08 02 03 FF")
def on_LCrelease(self, event):
LeftHost = '10.30.1.41'
port1 = 5678
LC = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
LC.connect((LeftHost, port1))
LC.send("81 01 06 01 08 08 03 03 FF")
if __name__ == "__main__":
root = tk.Tk()
Example(root).pack(side="top", fill="both", expand=True)
root.mainloop()
add --> bytes.fromhex in LC.send:: LC.send(bytes.fromhex("81 01 06 01 08 08 03 03 FF"))添加 --> bytes.fromhex 在 LC.send:: LC.send(bytes.fromhex("81 01 06 01 08 08 03 03 FF"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.