Python
Snippets
Dokumentation
python-handbuch.pdf vom 15.06.2019
python-beispiele.zip vom 15.06.2019
Python-IDE
Python.exe (neue Version vom 15.12.2021)
Python.zip (neue Version vom 15.12.2021)
PythonIDE_Delphi.exe (Delphi-Version 3.2, vom 06.10.2020)
Python-Hilfetexte-win.txt (Version 3.2, vom 07.07.2016)
Python-Hilfetexte-linux.txt (Version 3.2, vom 07.07.2016)
Python-Skripte umbenennen txt -> py
Python-IDE:
Python-Win: PythonIDE.py (Version 3.2, vom 07.07.2016)
Python-Unix: Unix_PythonIDE.py (Version 3.2, vom 07.07.2016)
Quellcode der WPF-IDE:
Prog-Python-IDE-WPF.zip (Version 3.3, vom 23.05.2018)
Quellcode der Delphi-IDE:
Python-Delphi.zip (Version 3.2, vom 07.07.2016)
Informationen über die Sprache Python
Lösungen einiger Python Probleme
Stichworte | Problem | Lösung |
Ausgabedeutscher Sonderzeichen | Wie kann man deutsche Sonderzeichen mit print ausgeben |
Am Anfang jedes Scripts: # coding=utf8 |
Key-press-Event | wie kann man das key-press-Event abfangen? |
def keyPress(self,event): print("Key Press Event:") print(" event.char:", event.char) print(" event.keysym:", event.keysym) print(" event.keycode:", event.keycode) print(" event.keysym_num:", event.keysym_num) |
Key-release-Event | wie kann man das key-release-Event abfangen? |
konstruktor: master.bind("<KeyRelease>", self.keyRelease) methode: def keyRelease(self,event): print("Key Release Event:") print(" event.char:", event.char) print(" event.keysym:", event.keysym) print(" event.keycode:", event.keycode) print(" event.keysym_num:", event.keysym_num) if event.keysym_num==65481: # F12 self.saveasFile() |
Program starten | wie kann man ein Programm starten? |
a) os.system(program) # synchron b) subprocess.call([program, "parameter"]) # synchron c)os.popen("notepad.exe") # asynchron in Python, synchron in QGis d) os.startfile(programm) # asynchron e) os.spawnl(mode, path, ...) f) os.spawnle(mode, path, ..., env) g) os.spawnlp(mode, file, ...) ih os.spawnlpe(mode, file, ..., env) ji os.spawnv(mode, path, args) j) os.spawnve(mode, path, args, env) k) os.spawnvp(mode, file, args) l) os.spawnvpe(mode, file, args, env)¶ Beispiel: os.spawnv(os.P_NOWAIT, "c:/windows/system32/cmd.exe",['/K', '']) |
Openfile | Wie ruft man einen Openfile-Dialog auf? |
filename = filedialog.askopenfilename(title="Dateien laden", initialdir="C:/P/UI", multiple=False, filetypes=( ("Pythondateien",".py" ),("Alle Dateien","*.*" ) ) ) if filename: self.filename = filename pathname=os.path.split(filename) # trennt path and filename messagebox.showinfo("Auswahl",filename) else: messagebox.showinfo("Auswahl","Abbruch") |
Savefile | Wie ruft man eine savefile-Dialog auf? |
filename = filedialog.asksaveasfilename(title="Dateien speichern unter", initialdir="D:/P/UI", filetypes=( ("Pythondateien",".py" ),("Alle Dateien","*.*" ) ) ) if filename: self.filename = filename pathname=os.path.split(filename) # trennt path and filename root.title("Python-IDE: "+pathname[1] ) messagebox.showinfo("Auswahl",filename) |
Strg+C | Methode Verknüpfen mit Strg+C |
Die Event-Methode hat zusätzlich den Parameter Event: self.editor.bind("<Control-Key-c>", self.copyClipboardEvent) self.editor.bind("<Control-Key-C>", self.copyClipboardEvent) def copyClipboardEvent(self,event): self.copyClipboard() def copyClipboard(self): try: text = self.editor.selection_get() except TclError: print("Select something") else: self.clipboard_clear() self.clipboard_append(text) |
Strg+V | Methode Verknüpfung mit Strg+V |
Die Event-Methode hat zusätzlich den Parameter Event:
self.editor.bind("<Control-Key-v>", self.insertFromClipboardEvent) self.editor.bind("<Control-Key-V>", self.insertFromClipboardEvent) def insertFromClipboardEvent(self,event): self.insertFromClipboard() # Aufruf der eigentlichen Methode def insertFromClipboard(self): cliptext = root.clipboard_get() print(cliptext) |
Clipboard | Abfrage des Clipboard |
cliptext = root.clipboard_get() print(cliptext) |
Clipboard | Einfügen in das Clipboard |
self.clipboard_clear() self.clipboard_append(text) |
Informationen über Python/Tkinter
Informationen über Python und OS
Eingebaute Standarddialoge in Tkinter
Literatur Python
Python 3
Johannes Ernesti, Peter Kaiser
Galileo Computing
ISBN 978-3-8362-1925-9