본문 바로가기
프로그래밍/python

[tkinter] 03. 버튼 만들기

by 한코코 2024. 4. 13.

from tkinter import *

root = Tk()

def myClick():
    myLabel = Label(root, text="Look! I clicked a Button!")
    myLabel.pack()

myButton = Button(root, text="Click Me!", padx=50, pady=50, command=myClick,fg="red", bg="black")
myButton.pack()

root.mainloop()

 

  • 가로 길이  padx
  • 세로 길이 pady
  • 버튼 눌렀을때 함수 실행할때는 ()를 붙이지 않는다 ➡️ ()을 붙이면 버튼을 누르기 전에 먼저 실행되기 때문
  • fg 글 색깔
  • bg 버튼 색깔이라는데 바뀌지 않는다. 왜그럴까.

출처 : https://www.youtube.com/watch?v=yuuDJ3-EdNQ&list=PLCC34OHNcOtoC6GglhF3ncJ5rLwQrLGnV&index=3

댓글