Advertisement
ahilon

Untitled

Jan 20th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. import pyautogui
  2. from tkinter import *
  3. from time import sleep
  4.  
  5. # budowa okienka
  6. root = Tk() # tworzenie okna głównego
  7. root.title("Mouse Coordinate")
  8. root.iconbitmap("paint.ico")
  9.  
  10. def mouse():
  11.     x, y = pyautogui.position()
  12.     positionStr = 'X ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4)
  13.     return positionStr
  14.  
  15. def colorPixel():
  16.     try:
  17.         x, y = pyautogui.position()
  18.         pixelColor = pyautogui.screenshot().getpixel((x, y))
  19.         color = ' RGB: (' + str(pixelColor[0]).rjust(3)
  20.         color += ', ' + str(pixelColor[1]).rjust(3)
  21.         color += ', ' + str(pixelColor[2]).rjust(3) + ')'
  22.         return color
  23.     except IndexError:
  24.         output =  ("po za skalą ")
  25.         return output
  26.  
  27.  
  28. mouseValue = StringVar()
  29. colorPixelValue = StringVar()
  30.  
  31. mouseValue.set(mouse())
  32. colorPixelValue.set(colorPixel())
  33.  
  34. mouseCoordinate = Label(root, width=40 , textvariable = mouseValue)
  35. pixelColor = Label(root, width=40, textvariable = colorPixelValue)
  36.  
  37.  
  38. mouseCoordinate.grid(row=0, column=0, columnspan=3, padx=10, pady=10)
  39.  
  40. pixelColor.grid(row=1, column=0, columnspan=3, padx=10, pady=10)
  41.  
  42. while True:
  43.     try:
  44.         mouseValue.set(mouse())
  45.         colorPixelValue.set(colorPixel())
  46.         root.update()
  47.     except TclError:
  48.         sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement