강의노트 위젯 위치 배치
조회수 118
• 댓글 0
• 수정 6개월 전
- 윈도우 프로그램
배치 방법
pack() 방법
위젯.pack(parameter) side 속성 : top, bottom, left, right "side = left" 는 왼쪽부터 채우라는 것이고 "side = right"은 오른쪽부터 채우라는 의미이다.
윈도우 창의 폭에 맞추는 방법은 "fill = X"이다.
위젯 사이에 여백을 주는 방법은 "padx = a픽셀값" 또는 "pady = b픽셀값"이다. x방향으로 여백을 a픽셀만큼, y방향으로 여백을 b픽셀만큼 준다.
내부 여백은 "ipadx = a픽셀" 또는 "ipady = b픽셀값"이다. 위젯 내부의 여백을 설정하는 명령어이다.
from tkinter import *
win = Tk()
win.geometry('400x400')
win.title('pack 함수')
lbl1 = Label(win, text='111111')
lbl2 = Label(win, text='222222')
lbl3 = Label(win, text='333333')
lbl4 = Label(win, text='444444')
lbl5 = Label(win, text='555555')
lbl6 = Label(win, text='666666')
lbl7 = Label(win, text='777777')
lbl8 = Label(win, text='888888')
lbl9 = Label(win, text='999999')
lbl1.pack(side='top')
lbl2.pack(side='bottom')
lbl3.pack(side='left')
lbl4.pack(side='right')
lbl5.pack(side='top')
lbl6.pack(side='left')
lbl7.pack(side='bottom')
lbl8.pack(side='right')
lbl9.pack(side='top')
win.mainloop()
anchor 속성 : n, ne, e, se, s, sw, w, nw, center
from tkinter import *
win = Tk()
win.geometry('250x250')
win.title('pack 함수')
lbl1 = Label(win, text='111111')
lbl2 = Label(win, text='222222')
lbl3 = Label(win, text='333333')
lbl4 = Label(win, text='444444')
lbl5 = Label(win, text='555555')
lbl6 = Label(win, text='666666')
lbl7 = Label(win, text='777777')
lbl8 = Label(win, text='888888')
lbl9 = Label(win, text='999999')
lbl1.pack(anchor='n')
lbl2.pack(anchor='ne')
lbl3.pack(anchor='e')
lbl4.pack(anchor='se')
lbl5.pack(anchor='s')
lbl6.pack(anchor='sw')
lbl7.pack(anchor='w')
lbl8.pack(anchor='nw')
lbl9.pack(anchor='center')
win.mainloop()
현 위치에서 방위에 따라 놓인다.
파라미터 | 의미 | 속성 |
---|---|---|
side | 특정 위치로 할당 | top, bottom, left, right |
anchor |
grid 속성
행과 열로 위젯을 붙인다. 행과 열을 건너뛸수는 없다.
from tkinter import *
win = Tk()
win.geometry('250x250')
win.title('pack 함수')
lbl1 = Label(win, text='111111')
lbl2 = Label(win, text='222222')
lbl3 = Label(win, text='333333')
lbl4 = Label(win, text='444444')
lbl5 = Label(win, text='555555')
lbl6 = Label(win, text='666666')
lbl7 = Label(win, text='777777')
lbl8 = Label(win, text='888888')
lbl9 = Label(win, text='999999')
lbl1.grid(row = 0, column = 0)
lbl2.grid(row = 0, column = 1)
lbl3.grid(row = 0, column = 2)
lbl4.grid(row = 1, column = 0)
lbl5.grid(row = 1, column = 1)
lbl6.grid(row = 1, column = 2, rowspan=2)
lbl7.grid(row = 2, column = 0, columnspan=2)
lbl8.grid(row = 3, column = 0)
lbl9.grid(row = 3, column = 1)
win.mainloop()
place
tkinter창의 절대 위치에 배치한다. "place(x = x좌표, y = y좌표, width = 폭, height = 높이)"의 형식으로 지정된다. width와 height이 생략되면 원 위젯의 크기로 나타난다.
이전 글
다음 글
로그인 하면 댓글을 쓸 수 있습니다.