Advertisement
here2share

# Tk_Zero_Window_Frame_2.py

Sep 29th, 2020 (edited)
1,427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. # Tk_Zero_Window_Frame_2.py -- sort of hack
  2.  
  3. ttt = 'Drag This Label'
  4.  
  5. try:
  6.     from Tkinter import *
  7. except:
  8.     from tkinter import *
  9.    
  10. import time
  11. from ctypes import windll, Structure, c_ulong, byref
  12. import ctypes
  13.  
  14. mask = "#393939"
  15.  
  16. cw = 400
  17. ch = 200
  18. root = Tk()
  19. ww = root.winfo_screenwidth()
  20. hh = root.winfo_screenheight()
  21. root.geometry(str(ww+10)+"x"+str(hh+10)+"+-10+-32") # to hide the frame
  22. root.title('Zero Window Frame 2')
  23. root.attributes("-transparentcolor", mask)
  24. root.configure(background=mask)
  25. canvas = Canvas(root, width=cw, height=ch, bg='darkgray')
  26. canvas.place(x=100,y=100)
  27. root.pack_propagate(0)
  28.  
  29. class POINT(Structure):
  30.     _fields_ = [("x", c_ulong), ("y", c_ulong)]
  31.  
  32. def onLeftClick(event):
  33.     xx,yy = event.x,event.y
  34.     if xx > cw-25:
  35.         if yy < 35:
  36.             root.destroy()
  37.     prev[0] = (xx,yy)
  38.  
  39. def onLeftDrag(event):
  40.     # xx,yy = event.x, event.y
  41.     pt = POINT()
  42.     windll.user32.GetCursorPos(byref(pt))
  43.     x1, y1 = prev[0]
  44.     x2, y2 = pt.x, pt.y
  45.     t = 'X=%s Y=%s' % (x2,y2)
  46.     canvas.itemconfigure(info,text=t)
  47.     canvas.place(x=x2-x1,y=y2-y1)
  48.  
  49. xy = 0
  50. prev = [0]
  51. font_a = ('arial', 24, 'bold')
  52. font_b = ('verdana', 32, 'bold')
  53. canvas.create_text((cw/2,ch/2), anchor=CENTER, text=ttt, fill='purple', font=font_b)
  54. exit = canvas.create_text((cw-15,20), text='X', fill='red', font=font_a)
  55. info = canvas.create_text((cw/2,ch/2-50), anchor=CENTER, text='***', fill = 'black', font=font_a)
  56. canvas.bind('<B1-Motion>', onLeftDrag )
  57. canvas.bind('<Button-1>' , onLeftClick)
  58. canvas.focus()
  59.  
  60. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement