Advertisement
here2share

# wutyewcie_tk.py

Jul 14th, 2022 (edited)
1,267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.45 KB | None | 0 0
  1. # wutyewcie_tk.py zzz (pronounced as what-you-see)
  2.  
  3. # 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.
  4.  
  5. import tkinter as tk
  6. import random
  7.  
  8. def wutyewcie_tk(width=300, height=300):
  9.  canvas.config(width=width, height=height)
  10.  for x in range(1,width,50):
  11.   canvas.create_line(x,0, x,height)
  12.  for y in range(1,height,50):
  13.   canvas.create_line(0,y, width,y)
  14.  canvas.create_rectangle(51,51, 101,101, fill="red",
  15.         activefill='green', tag="R")
  16. 0
  17. root = tk.Tk()
  18. canvas = tk.Canvas()
  19. canvas.pack()
  20. canvas.click = False
  21. canvas.Lshift = False
  22.  
  23. def default_bind():
  24.  canvas.tag_bind("R", "<Button-1>", onClick1)
  25.  canvas.tag_bind("R", "<B1-Motion>", onMotion1)
  26.  canvas.tag_bind("R", "<ButtonRelease-1>",onRelease1)
  27.  root.bind("<Key>", onKeyPress)
  28.  root.bind("<KeyRelease>", onKeyRelease)
  29. def onKeyPress(event):
  30.  key = event.keysym
  31.  if key in 'Shift_L':
  32.   canvas.Lshift = True
  33. def onKeyRelease(event):
  34.  key = event.keysym
  35.  if key in 'Shift_L':
  36.   canvas.Lshift = False
  37. def onClick1(event):
  38.  canvas.click = event.x, event.y
  39. def onMotion1(event):
  40.  x, y = canvas.click
  41.  dx = event.x - x
  42.  dy = event.y - y
  43.  canvas.move('current' ,dx ,dy)
  44.  canvas.click = event.x, event.y
  45. def onRelease1(event):
  46.  rx, ry = event.x, event.y
  47.  canvas.click = 0
  48. 0
  49. def make_draggable(widget):
  50.  widget.bind("<Button-1>", on_drag_start)
  51.  widget.bind("<B1-Motion>", on_drag_motion)
  52.  widget.bind("<ButtonRelease-1>",on_drag_release)
  53. def on_drag_start(event):
  54.  widget = event.widget
  55.  widget._drag_start_x = event.x
  56.  widget._drag_start_y = event.y
  57. def on_drag_motion(event):
  58.  global widget
  59.  widget = event.widget
  60.  if canvas.Lshift:
  61.   x = widget.winfo_x()
  62.   y = widget.winfo_y()
  63.   dx, dy = max(20,event.x+30), max(20,event.y+30)
  64.   widget.destroy()
  65.   widget = frame_test(x,y,dx,dy)
  66.   make_draggable(widget)
  67.  else:
  68.   dx = widget.winfo_x() - widget._drag_start_x + event.x
  69.   dy = widget.winfo_y() - widget._drag_start_y + event.y
  70.   widget.place(x=dx ,y=dy)
  71. def on_drag_release(event):
  72.  default_bind()
  73.  
  74. default_bind()
  75.  
  76. def frame_test(xx=100,yy=50,w=160,h=32):
  77.  global frame, entry
  78.  frame = tk.Frame(canvas, bg='#80c1ff', bd=5)
  79.  frame.place(x=xx,y=yy,width=w,height=h) #
  80.  
  81.  entry = tk.Entry(frame, font=14)
  82.  entry.place(width=90,height=20)
  83.  return frame
  84.  
  85. frame_test()
  86.  
  87. make_draggable(frame)
  88.  
  89. wutyewcie_tk()
  90. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement