Skip to content
- tkinter 라이브러리
- GUI 용 파이썬 표준 라이브러리
- Tcl/Tk 프로그래밍 언어의 GUI 툴킷인 Tk를 사용
- GUI 화면 생성
- 메인 창(Tk 객체) 생성
- 위젯 생성
- 위젯을 창에 배치
- 메인 루프 실행
- 생성 예 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#!/usr/bin/env python # -*- coding:utf-8 -*- from tkinter import * def f_turn(): print('button click') window = Tk() label = Label(window, text = 'press button') label.pack() button = Button(window, text='Hello Button', command=f_turn) button.pack() window.mainloop() |
- 생성 예 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#!/usr/bin/env python # -*- coding:utf-8 -*- import tkinter as tk def f_turn(msg): #label.config(text=msg) label.config(text=button.cget('text')) window = tk.Tk() label = tk.Label(window, text='press button') label.pack() button = tk.Button(window, text='Hello Button', command=lambda:f_turn('hello')) button.pack() window.mainloop() |
error: Content is protected !!