I started making a simple drawing program, to use for a level maker, and I came across a slight issue
from Tkinter import *
class Main:
def __init__(self,root):
w,h = root.winfo_screenwidth(), root.winfo_screenheight()
current = {}
canvas = Canvas(root, width = w, height = h, bd=0)
canvas.pack()
root.overrideredirect(1)
root.geometry("%dx%d+0+0" % (w, h))
def save(event):#save all tiles to file for use. ## not implemented yet
for x in canvas.find_all():
print canvas.coords(x)
root.destroy()
def Start(event):#start drawing
current["x"],current["y"] = event.x,event.y
def Stretch(event):#change second coords to stretch tile
for x in canvas.find_withtag("current"):
canvas.delete(x)
canvas.create_rectangle(current["x"],current["y"],event.x,event.y,tags="current")
def Stop(event):#end drawing
for x in canvas.find_withtag("current"):
canvas.delete(x)
canvas.create_rectangle(current["x"],current["y"],event.x,event.y)
menu = Canvas(canvas, width = 100, height = 50, bg="Blue")
menu.bind("<Button-1>",save)#so you don't have to alt-f4
menu.place(x = w/2-50, y = h/2-25)
canvas.bind("<Button-1>",Start)
canvas.bind("<B1-Motion>",Stretch)#all important bindings
canvas.bind("<ButtonRelease-1>",Stop)
root = Tk()
Main(root)
root.wait_window()
If you try to start a new rectangle on the edge of an existing rectangle, it deletes the existing one.
You can end on an existing rectangle, or just leave them free floating. Which is really confusing me.
Any help would be appreciated.