일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- numpy
- Excel
- Tkinter
- google apps script
- Kotlin
- Google Spreadsheet
- dataframe
- matplotlib
- c#
- Mac
- math
- Redshift
- PANDAS
- list
- hive
- Apache
- Google Excel
- PySpark
- array
- Github
- 파이썬
- Java
- gas
- django
- GIT
- SQL
- Python
- string
- PostgreSQL
- Today
- Total
달나라 노트
Python tkinter : place_info (객체의 위치 정보, 객체의 position, 객체 위치 좌표) 본문
Python tkinter : place_info (객체의 위치 정보, 객체의 position, 객체 위치 좌표)
CosmosProject 2022. 5. 17. 21:43
Label, Button같은 어떤 객체는 Window의 어느 부분에 표시될지에 대한 위치 정보를 가지고 있습니다.
place_info method는 이러한 객체들의 현재 위치정보를 담은 dictionary를 return합니다.
import tkinter as tk
window = tk.Tk()
window.geometry('1000x400')
label = tk.Label(window, text='Label')
label.place(x=10, y=15)
dict_info = label.place_info()
print(dict_info)
print('x =', dict_info['x'])
print('y =', dict_info['y'])
window.mainloop()
위 코드는 Label의 위치 정보를 출력해주는 기능을 하도록 작성한 코드입니다.
{'in': <tkinter.Tk object .>, 'x': '10', 'relx': '0', 'y': '15', 'rely': '0', 'width': '', 'relwidth': '', 'height': '', 'relheight': '', 'anchor': 'nw', 'bordermode': 'inside'}
x = 10
y = 15
위 코드를 실행하면 Window가 뜨면서 terminal에는 위같은 정보가 출력됩니다.
- dict_info = label.place_info()
위 부분처럼 label.place_info()는 Label의 위치 정보를 담은 dictionary를 얻을 수 있습니다.
{'in': <tkinter.Tk object .>, 'x': '10', 'relx': '0', 'y': '15', 'rely': '0', 'width': '', 'relwidth': '', 'height': '', 'relheight': '', 'anchor': 'nw', 'bordermode': 'inside'}
dictionary 내용을 보면 위와 같은데 여기서 key = 'x'인 값이 Label 위치의 x 좌표이며 key = 'y'인 값이 Label 위치의 y 좌표입니다.
- label.place(x=10, y=15)
처음에 Label 생성 시 Label의 위치를 x=10, y=15로 설정했기 때문에 이것이 그대로 출력되는 것을 볼 수 있습니다.
import tkinter as tk
window = tk.Tk()
window.geometry('1000x400')
button = tk.Button(window, text='Button')
button.place(x=10, y=15)
dict_info = button.place_info()
print(dict_info)
print('x =', dict_info['x'])
print('y =', dict_info['y'])
window.mainloop()
place_info는 Button 객체에도 존재합니다.
{'in': <tkinter.Tk object .>, 'x': '10', 'relx': '0', 'y': '15', 'rely': '0', 'width': '', 'relwidth': '', 'height': '', 'relheight': '', 'anchor': 'nw', 'bordermode': 'inside'}
x = 10
y = 15
위 코드를 실행하면 위처럼 Button 객체의 위치 정보가 출력됩니다.