#!/usr/bin/env python
from socket import *
from time import ctime
#import RPi.GPIO as GPIO
from Tkinter import *
from threading import Thread
import time
from random import randint
## Klasse Netzwerk
class Netzwerk(Thread):
def run(self):
HOST = ''
PORT = 8091
BUFSIZ = 1024 # Size buffer
ADDR = (HOST, PORT)
tcpSerSock = socket(AF_INET, SOCK_STREAM) # Socket erstellen
tcpSerSock.bind(ADDR) # IP und Port
tcpSerSock.listen(5)
while True:
print 'Waiting for connection...'
tcpCliSock, addr = tcpSerSock.accept()
print '...connected from :', addr # IP Adresse vom Client
while True:
data = tcpCliSock.recv(BUFSIZ) # Empfang vom Client und in data speichern
if not data:
break
if data == '1':
############################### hier soll der Aufruf der Methode hin zb. ausloeser(1)
print 'test1'
elif data == '2':
print 'test2'
else:
print "%s" % data
## Thread starten Netzwerk
thread1 = Netzwerk()
thread1.start()
## GUI
# Ereignisverarbeitung
def lokomotiveEins(augen):
# Anzeige der Daten
if augen == 1:
lok.config(image=lokLinks)
lok.place(x=0, y=205, width=200, height=100)
elif augen == 2:
lok.config(image=lokRechts)
lok.place(x=300, y=55, width=200, height=100)
elif augen == 3:
lok.config(image=lokLinks)
lok.place(x=500, y=95, width=200, height=100)
# Erzeugung des Fensters
tkFenster = Tk()
tkFenster.title('Eisenbahn')
#tkFenster.geometry('750x450')
tkFenster.geometry('1500x900')
# Bilder
imageHintergrund = PhotoImage(file='gleisbett.gif')
lokLinks = PhotoImage(file='lokLinks.gif')
lokRechts = PhotoImage(file='lokRechts.gif')
# Canvas fuer den Hintergrund
frame = Canvas(master=tkFenster)
frame.place(x=0, y=0, width=1381, height=713)
frame.create_image(0, 0, image=imageHintergrund, anchor='nw')
# Label Wuerfel mit Bild
lok = Label(master=frame, image=lokLinks)
######################################### aufrufen der Methode
# aendern der Bilder
def ausloeser(uebergabe):
Button(master=frame, command=lokomotiveEins(uebergabe))
################################################
# Aktivierung des Fensters
tkFenster.mainloop()