Python
(파이썬) 버튼 위젯 크기 변경하기
코딩ABC
2023. 12. 1. 10:41
반응형
파이썬에서 버튼 위젯의 크기를 조절하는 방법입니다.
1. 기본적인 버튼의 크기는 버튼의 text 속성에 있는 텍스트의 크기로 설정됩니다.
from tkinter import *
win = Tk()
button1 = Button(win, text='버튼 1')
button2 = Button(win, text='버튼 2')
button1.place(x=50, y=50)
button2.place(x=120, y=50)
mainloop()
2. 버튼.place() 함수의 width, height 속성으로 크기 조절하기
from tkinter import *
win = Tk()
button1 = Button(win, text='버튼 1')
button2 = Button(win, text='버튼 2')
button1.place(x=50, y=10, width=100, height=50)
button2.place(x=50, y=80, width=100, height=50)
mainloop()
place 함수는 ipadx, padx와 같은 속성을 사용할 수 없습니다.
3. padx, ipadx, pady, ipady 속성으로 크기 조절하기
from tkinter import *
win = Tk()
button1 = Button(win, text='버튼 1')
button2 = Button(win, text='버튼 2')
button1.pack();
button2.pack();
mainloop()
from tkinter import *
win = Tk()
button1 = Button(win, text='버튼 1')
button2 = Button(win, text='버튼 2')
button1.pack(padx=50, pady=10, ipadx=20, ipady=10)
button2.pack(padx=50, pady=10, ipadx=20, ipady=10)
mainloop()
fill=X 속성을 이용해서 버튼의 크기를 윈도우 창의 가로 크기 만큼 채울 수 있습니다.
from tkinter import *
win = Tk()
win.geometry("300x150")
button1 = Button(win, text='버튼 1', bg='yellow')
button2 = Button(win, text='버튼 2', bg='green')
button1.pack(fill=X, ipady=10)
button2.pack(fill=X, ipady=10)
mainloop()
반응형