Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # wutyewcie_tk.py zzz (pronounced as what-you-see)
- # this project is intended to make tkinter far easier to work with many added features. i probably should have asked for help on this many years ago.
- import tkinter as tk
- import random
- def wutyewcie_tk(width=300, height=300):
- canvas.config(width=width, height=height)
- for x in range(1,width,50):
- canvas.create_line(x,0, x,height)
- for y in range(1,height,50):
- canvas.create_line(0,y, width,y)
- canvas.create_rectangle(51,51, 101,101, fill="red",
- activefill='green', tag="R")
- 0
- root = tk.Tk()
- canvas = tk.Canvas()
- canvas.pack()
- canvas.click = False
- canvas.Lshift = False
- def default_bind():
- canvas.tag_bind("R", "<Button-1>", onClick1)
- canvas.tag_bind("R", "<B1-Motion>", onMotion1)
- canvas.tag_bind("R", "<ButtonRelease-1>",onRelease1)
- root.bind("<Key>", onKeyPress)
- root.bind("<KeyRelease>", onKeyRelease)
- def onKeyPress(event):
- key = event.keysym
- if key in 'Shift_L':
- canvas.Lshift = True
- def onKeyRelease(event):
- key = event.keysym
- if key in 'Shift_L':
- canvas.Lshift = False
- def onClick1(event):
- canvas.click = event.x, event.y
- def onMotion1(event):
- x, y = canvas.click
- dx = event.x - x
- dy = event.y - y
- canvas.move('current' ,dx ,dy)
- canvas.click = event.x, event.y
- def onRelease1(event):
- rx, ry = event.x, event.y
- canvas.click = 0
- 0
- def make_draggable(widget):
- widget.bind("<Button-1>", on_drag_start)
- widget.bind("<B1-Motion>", on_drag_motion)
- widget.bind("<ButtonRelease-1>",on_drag_release)
- def on_drag_start(event):
- widget = event.widget
- widget._drag_start_x = event.x
- widget._drag_start_y = event.y
- def on_drag_motion(event):
- global widget
- widget = event.widget
- if canvas.Lshift:
- x = widget.winfo_x()
- y = widget.winfo_y()
- dx, dy = max(20,event.x+30), max(20,event.y+30)
- widget.destroy()
- widget = frame_test(x,y,dx,dy)
- make_draggable(widget)
- else:
- dx = widget.winfo_x() - widget._drag_start_x + event.x
- dy = widget.winfo_y() - widget._drag_start_y + event.y
- widget.place(x=dx ,y=dy)
- def on_drag_release(event):
- default_bind()
- default_bind()
- def frame_test(xx=100,yy=50,w=160,h=32):
- global frame, entry
- frame = tk.Frame(canvas, bg='#80c1ff', bd=5)
- frame.place(x=xx,y=yy,width=w,height=h) #
- entry = tk.Entry(frame, font=14)
- entry.place(width=90,height=20)
- return frame
- frame_test()
- make_draggable(frame)
- wutyewcie_tk()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement