Hi,
so hier mal den ganze Code, der auch wirklich funktioniert.
Den Server von WDR nutze ich nur damit ich das hier testen kann, weil ich mansch mal nicht an meinen Server dran komme.
Und wie gesagt ich habe 0,nix Ahnung von TCP und UDP usw.
Das war halt erstmal ein Versuch, wie ich mir das gedacht habe.
Code: Alles auswählen
# -*- coding: utf-8 -*-
from tkinter import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.uic import *
import urllib.request
import urllib
app = QApplication(sys.argv)
widget = loadUi('Tu.ui')
def TonAn():
widget.TonStatus.setText("Ton ist an!!")
def TonAus():
widget.TonStatus.setText("Ton ist aus")
def BildAnzeigen(x):
global zahl
global testZahl
if (zahl%2 == 0):
#PfadCam = 'http://11.11.11.134/Streaming/channels/1/picture.jpg'
PfadCam = 'http://www.wdr.de/themen/global/webcams/domcam/domcam_960_live.jpg'
print (PfadCam)
else:
IpCamText = widget.LineEditCam.displayText()
#PfadCam = 'http://' + IpCamText + '/themen/global/webcams/domcam/domcam_960_live.jpg'
PfadCam = 'http://' + IpCamText + '/Streaming/channels/1/picture.jpg'
print(PfadCam)
url = PfadCam
data = urllib.request.urlopen(url).read()
pixmap = QPixmap()
pixmap.loadFromData(data)
icon = QPixmap(pixmap)
widget.BildAnzeige.setPixmap(QPixmap(icon).scaled(600, 500))
def MumbelServerConnect():
global zahl2
if (zahl2 % 2 == 0):
print('feste IP')
#SH Script hier!
else:
IpMumbalText = widget.LineEditMumbel.displayText()
PfadMumbal = IpMumbalText
print(PfadMumbal)
#SH script hier!
def MumbelServerDisconnect():
print('Server verlassen')
#SH Script hier
def BildSchwarz():
widget.BildAnzeige.setPixmap(QPixmap('Testbild2.jpg').scaled(600, 500))
def IpCamVeraenderbar():
global zahl
zahl = float(zahl) + 1
if (zahl%2 == 0):
widget.LineEditCam.setDisabled(True)
else:
widget.LineEditCam.setDisabled(False)
def IpMumbelVeraenderbar():
global zahl2
zahl2 = float(zahl2) + 1
if (zahl2 % 2 == 0):
widget.LineEditMumbel.setDisabled(True)
else:
widget.LineEditMumbel.setDisabled(False)
def Auf():
#SH Script hier!
print ('Auf')
#Button
widget.ButtonTon.clicked.connect(TonAn)
widget.ButtonTon.clicked.connect(BildAnzeigen)
widget.ButtonTon.clicked.connect(MumbelServerConnect)
widget.ButtonAuf.clicked.connect(Auf)
widget.ButtonAus.clicked.connect(TonAus)
widget.ButtonAus.clicked.connect(BildSchwarz)
widget.ButtonAus.clicked.connect(MumbelServerDisconnect)
#Setup
widget.CheckBoxCam.stateChanged.connect(IpCamVeraenderbar)
widget.CheckBoxMumbel.stateChanged.connect(IpMumbelVeraenderbar)
for Startschleife in range (0, 1):
BildSchwarz()
TonAus()
zahl = 1
zahl2 = 1
testZahl = 0
IpCamVeraenderbar()
IpMumbelVeraenderbar()
print('Erster Durchlauf beendet')
widget.show()
sys.exit(app.exec_())
[codebox=xml file=Unbenannt.xml]
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1022</width>
<height>598</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="ButtonTon">
<property name="geometry">
<rect>
<x>670</x>
<y>310</y>
<width>121</width>
<height>101</height>
</rect>
</property>
<property name="text">
<string> Ton An</string>
</property>
</widget>
<widget class="QPushButton" name="ButtonAus">
<property name="geometry">
<rect>
<x>850</x>
<y>310</y>
<width>121</width>
<height>101</height>
</rect>
</property>
<property name="text">
<string>Ton Aus</string>
</property>
</widget>
<widget class="QLabel" name="BildAnzeige">
<property name="geometry">
<rect>
<x>40</x>
<y>20</y>
<width>601</width>
<height>501</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
<widget class="QTabWidget" name="tabWidget">
<property name="geometry">
<rect>
<x>660</x>
<y>10</y>
<width>321</width>
<height>261</height>
</rect>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Anzeige</string>
</attribute>
<widget class="QLabel" name="TonStatus">
<property name="geometry">
<rect>
<x>90</x>
<y>20</y>
<width>111</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Ton Status !!</string>
</property>
</widget>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Setup</string>
</attribute>
<widget class="QLineEdit" name="LineEditCam">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>120</x>
<y>30</y>
<width>113</width>
<height>25</height>
</rect>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
</widget>
<widget class="QLineEdit" name="LineEditMumbel">
<property name="geometry">
<rect>
<x>120</x>
<y>80</y>
<width>113</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QCheckBox" name="CheckBoxCam">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>260</x>
<y>30</y>
<width>101</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QCheckBox" name="CheckBoxMumbel">
<property name="geometry">
<rect>
<x>260</x>
<y>80</y>
<width>101</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLabel" name="LabelIpCam">
<property name="geometry">
<rect>
<x>20</x>
<y>30</y>
<width>68</width>
<height>19</height>
</rect>
</property>
<property name="text">
<string>IP Cam</string>
</property>
</widget>
<widget class="QLabel" name="LabelIpMumbel">
<property name="geometry">
<rect>
<x>20</x>
<y>80</y>
<width>91</width>
<height>19</height>
</rect>
</property>
<property name="text">
<string>IP Mumbel</string>
</property>
</widget>
</widget>
</widget>
<widget class="QPushButton" name="ButtonAuf">
<property name="geometry">
<rect>
<x>671</x>
<y>430</y>
<width>301</width>
<height>101</height>
</rect>
</property>
<property name="text">
<string>Auf</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1022</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
[/code]
Zum Hintergrund.
Kamera hängt über der Eingangstür und Tür soll über ein Relais geöffnet werden.
So hoffe mal das passt so
Grüße