Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import csv
- from tkinter import Tk, Canvas, mainloop, SW
- #Klasse Bahnhof
- class Bahnhof(object):
- def __init__(self, name, breite, laenge):
- self.name = name
- self.breite = float(breite)
- self.laenge = float(laenge)
- def isHbf(self):
- return "Hbf" in self.name
- #Parsen der csv-Datei und Erzeugen der Bahnhöfe
- alleBahnhoefe = []
- with open("D_Bahnhof_2016_01_alle.csv") as csv_file:
- reader = csv.reader(csv_file,delimiter=';')
- for row in reader:
- alleBahnhoefe.append(Bahnhof(row[2],row[4],row[5]))
- #Bestimmen der max/min Breiten und Längen
- maxLaenge = max(bahnhof.laenge for bahnhof in alleBahnhoefe)
- minLaenge = min(bahnhof.laenge for bahnhof in alleBahnhoefe)
- maxBreite = max(bahnhof.breite for bahnhof in alleBahnhoefe)
- minBreite = min(bahnhof.breite for bahnhof in alleBahnhoefe)
- #Zeichnen der Punkte
- master = Tk()
- canvas_width = 600
- canvas_height = 600
- w = Canvas(master, width=canvas_width, height=canvas_height)
- w.pack()
- #Normale Bahnhöfe in Blau
- for curBahnhof in alleBahnhoefe:
- actLaenge = (canvas_width) / (maxLaenge-minLaenge) * (curBahnhof.laenge-minLaenge);
- actBreite = (canvas_height) / (maxBreite-minBreite) * (curBahnhof.breite-minBreite);
- actX = int(actBreite);
- actY = int(canvas_height-actLaenge);
- if curBahnhof.isHbf():
- w.create_oval(actX,actY, actX+5,actY+5, fill="#ff0000")
- w.create_text(actX+5,actY+5,text=curBahnhof.name[:2], fill="#ff0000",
- anchor=SW, activefill="yellow")
- else:
- w.lower(w.create_oval(actX,actY, actX+5,actY+5, fill="#000000"))
- mainloop()
Advertisement
Add Comment
Please, Sign In to add comment