Created
April 21, 2017 12:41
-
-
Save Vftdan/d0c3337b4069358c9ebad7780717ba8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tkinter | |
def click_listen1(e): | |
global lin | |
#e.widget.create_line(0, 0, e.x, e.y, fill = "#ffff00", width = 4) | |
#e.widget.coords(lin, *(0, 0, e.x, e.y, e.x -100, e.y - 100)) | |
if(lin): | |
lin_c.append(e.x) | |
lin_c.append(e.y) | |
e.widget.coords(lin, *lin_c) | |
else: | |
lin_c.append(e.x) | |
lin_c.append(e.y) | |
lin = e.widget.create_line(e.x, e.y, e.x, e.y, fill = "#ffff00", width = 4) | |
def click_listen2(e): | |
global lin, lin_c | |
#lin_c.append(lin_c[0]) | |
#lin_c.append(lin_c[1]) | |
svg.write(""" | |
<polyline points = '""" + ' '.join(list(map(str, lin_c))) + """' style = 'stroke:#ffff00; stroke-width:4; fill: transparent'></polyline> | |
""") | |
lin = False | |
lin_c = [] | |
def init_canv(): | |
global canv, svg | |
canv = tkinter.Canvas(mw, background = "#00ffff", width = 480, height = 320) | |
canv.pack() | |
svg = open("svg.html", "w+") | |
svg.write(""" | |
<html><body><svg style = 'background: #00ffff; height:320px; width: 480px;'> | |
""") | |
canv.bind("<Button-1>", click_listen1) | |
canv.bind("<Button-3>", click_listen2) | |
#print("qwe") | |
def save_svg(e): | |
svg.write(""" | |
</svg></body></html> | |
""") | |
svg.close() | |
mw = tkinter.Tk() | |
print(""" | |
Добро пожаловать в векторный графический редактор! | |
Версия: prealpha 0.0.0 | |
Управление: | |
* ЛКМ\t- установить узел полилинии | |
* ПКМ\t- завершить полилинию (без установки узла) | |
* save\t- сохранить в файл svg.html | |
Повторное сохранение за сессию не предусмотрено | |
Контакты: | |
* vftdan@gmail.com | |
* vftdan.github.io | |
""") | |
save_but = tkinter.Button(mw, text = "save") | |
save_but.pack() | |
canv, svg = 0, 0 | |
init_canv() | |
lin = False | |
lin_c = [] | |
#lin = canv.create_line(0, 0, 400, 400, fill = "#ffff00", width = 4) | |
save_but.bind("<Button-1>", save_svg) | |
mw.MainLoop() | |
#create_oval(*outer_rect) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment