전체 소스코드
import tkinter.messagebox as msgbox
from tkinter import *
root = Tk()
root.title("GUI")
root.geometry("300x150")
Label(root, text="메뉴를 선택해주세요").pack(side="top")
Button(root, text="주문하기").pack(side="bottom")
#메뉴 프레임
frame_burger = Frame(root, relief="solid", bd=1)
frame_burger.pack(side="left", fill="both", expand=True)
Button(frame_burger, text="햄버거").pack()
Button(frame_burger, text="치즈버거").pack()
Button(frame_burger, text="치킨버거").pack()
#음료 프레임
frame_drink = LabelFrame(root, text="음료")
frame_drink.pack(side="right", fill="both", expand=True)
Button(frame_drink, text="콜라").pack()
Button(frame_drink, text="사이다").pack()
root.mainloop()
Frame
프레임을 사용하면 위젯을 묶어서 나눌 수 있다
.relief 경계선을 설정할 수 있다
bd를 써줘야 외곽선 표시된다
LabelFrame은 테두리에 이름을 써넣을 수 있다
frame_burger = Frame(root, relief="solid", bd=1)
frame_burger.pack(side="left", fill="both", expand=True)
Button(frame_burger, text="햄버거").pack()
Button(frame_burger, text="치즈버거").pack()
Button(frame_burger, text="치킨버거").pack()
#음료 프레임
frame_drink = LabelFrame(root, text="음료")
frame_drink.pack(side="right", fill="both", expand=True)
Button(frame_drink, text="콜라").pack()
Button(frame_drink, text="사이다").pack()

side=를 설정하면 상하좌우 방향의 끝으로 붙는다

fill="both", expand=True를 차례로 적용한 결과이다
fill="both"는 상하좌우로 펼쳐준다
fill, expand를 사용하면 어떻게 달라지는지는

Difference between "fill" and "expand" options for tkinter pack method
I know this is a too trivial question, but I am new to python, and I have just started using the tkinter module. I have actually looked up about it everywhere, and I am unable to find the satisfact...
stackoverflow.com
이 링크에 사진으로 포함되어있다


위 아래로 라벨과 버튼을 넣어주었다


'python > tkinter' 카테고리의 다른 글
[Python tkinter GUI] #14 Grid(그리드) (0) | 2022.12.16 |
---|---|
[Python tkinter GUI] #13 Scrollbar(스크롤바) (0) | 2022.12.16 |
[Python tkinter GUI] #11 MessageBox(메세지박스) (0) | 2022.12.16 |
[Python tkinter GUI] #10 Menu(메뉴) (0) | 2022.12.16 |
[Python tkinter GUI] #9 Progessbar(진행바) (0) | 2022.12.16 |
댓글