Tkinter GUI based applications बनाने के लिए व्यापक रूप से उपयोग किया जाता है। इसमें कई toolkits और functions या modules उपलब्ध हैं जिनका उपयोग किसी particular application के विभिन्न attributes को define करने के लिए किया जा सकता है। GUI applications बनाने के लिए यह buttons, text boxes और labels सहित कुछ widgets प्रदान करता है। हम अन्य functions और libraries का उपयोग करके tkinter frame पर widget की position और इसके coordinates को customize कर सकते हैं।
मान लीजिए हमने एक text label widget बनाया है जिसकी tkinter frame में कुछ position है। अब, widget के actual coordinates प्राप्त करने के लिए, हम tkinter के library में उपलब्ध geometry methods का उपयोग कर सकते हैं।
हम winfo_rootx() और winfo_rooty() functions का उपयोग करेंगे जो frame या window के संबंध में widget के actual coordinates return करते हैं।
उदाहरण
# Import the tkinter library
from tkinter import *
# Create an instance of the tkinter frame
win = Tk()
# Define the geometry of the frame
win.geometry("600x400")
# Define the text-widget
my_text = Text(win, height=5, width=52)
# Create label
lab = Label(win, text="TutorialsPoint.com")
# Configure it using other properties
lab.config(font=("Helvetica", 20))
# Create a button widget
my_button = Button(text="Hello")
# Define the position of the widget
my_button.place(x=100, y=100)
# Update the coordinates with respect to the tkinter frame
win.update()
# Get the coordinates of both text widget and button widget
widget_x1, widget_y1 = my_button.winfo_rootx(), my_button.winfo_rooty()
widget_x2, widget_y2 = my_text.winfo_rootx(), my_button.winfo_rooty()
lab.pack()
print(widget_x1, widget_y1)
print(widget_x2, widget_y2)
# Keep the window running
win.mainloop()
आउटपुट
उपरोक्त code snippet चलाने से widget की current position print होगी:
134 157 0 157
