Advertisement
here2share

# Tk_find_xy_of_label.py

Oct 25th, 2021
1,351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. # Tk_find_xy_of_label.py
  2.  
  3. from Tkinter import *
  4.  
  5. #Import the tkinter library
  6.  
  7. #Create an instance of the tkinter frame
  8. win = Tk()
  9.  
  10. #Define the geometry of the frame
  11. win.geometry("600x200")
  12.  
  13. #Create a button widget
  14. my_label = Label(win, text="Move Window About And Look At The XY Of It")
  15.  
  16. #Configure it using other properties
  17. my_label.config(font =("Helvetica", 20))
  18.  
  19. #Define the position of the widget
  20. my_label.place(x=14, y=0)
  21.  
  22.  
  23.  
  24. while 1:
  25.     #Update the coordinates with respect to the tkinter frame
  26.     win.update()
  27.  
  28.     #Get the coordinates label widget
  29.     widget_x1, widget_y1 = my_label.winfo_rootx(), my_label.winfo_rooty()
  30.  
  31.     print (widget_x1, widget_y1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement