Tkinter: Difference between revisions

From 탱이의 잡동사니
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
== Overview ==
== Overview ==
Python graphic library tkinter 내용 정리
Python graphic library tkinter 내용 정리.
 
== Concept ==
=== Widgets ===
위젯은 화면에서 볼수 있는 모든 것들이다. 예를 들면 button, entry, label, frame 등이 있다.
 
==== Widget Classes ====
위젯들은 버튼, 프레임 등으로 나타나는 클래스들의 오브젝트이다. 때문에 위젯을 사용하고자 한다면 먼저 초기화를 해주어야 한다.
 
==== Window hierarchy ====
 
==== Configuration options ====
모든 위젯들은 저마다의 다른 configuration option 들을 가지고 있다. 이 옵션들은 어떻게 display 되는지 혹은 어떻게 동작하는지를 조절하게 된다.
 
사용 가능한 옵션들은 위젯에 따라 달라진다. 하지만 많은 옵션들에 대해서 일관성을 유지하고 있어서 사용법이 그리 다르지는 않다. 예를 들면 button 과 label 위젯에는 "text" 라는 옵션이 있는데, display 되는 Text 를 조절하게 된다. 하지만 scrollbar 위젯에는 "text" 옵션이 없다(필요가 없으므로). 같은 이유로 "button" 위젯에는 "command" 라는 옵션이 있는 것에 반해, label 위젯에는 해당 옵션이 존재하지 않는다.
 
옵션 설정은 최초 위젯 생성시에 지정이 가능하며, 생성 이후에도 일부 예외를 제외하고는 대부분 변경이 가능하다. 어떤 옵션들이 사용가능한지 정확히 알지 못하는 경우에는 가능한 옵션이 어떤 것들이 있는지 물어볼 수도 있다.
<source lang=python>
pchero@mywork:~$ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from Tkinter import *
>>> from ttk import *
>>> root = Tk()
>>> button = Button(root, text="Hello", command="buttonpressed")
>>> button.grid()
>>> button['text']
'Hello'
>>> button['text'] = "good bye"
>>> button.configure("text")
('text', 'text', 'Text', '', 'good bye')
>>> button.configure()
{'cursor': ('cursor', 'cursor', 'Cursor', '', ''), ...
</source>
 


== See also ==
== See also ==
Line 6: Line 41:
* http://zetcode.com/gui/tkinter/ - Tkinter tutorial
* http://zetcode.com/gui/tkinter/ - Tkinter tutorial
* http://www.python-course.eu/python_tkinter.php - Python Tkinter tutorial
* http://www.python-course.eu/python_tkinter.php - Python Tkinter tutorial
* http://www.tkdocs.com/tutorial/firstexample.html


[[category:python]]
[[category:python]]

Revision as of 16:09, 2 December 2016

Overview

Python graphic library tkinter 내용 정리.

Concept

Widgets

위젯은 화면에서 볼수 있는 모든 것들이다. 예를 들면 button, entry, label, frame 등이 있다.

Widget Classes

위젯들은 버튼, 프레임 등으로 나타나는 클래스들의 오브젝트이다. 때문에 위젯을 사용하고자 한다면 먼저 초기화를 해주어야 한다.

Window hierarchy

Configuration options

모든 위젯들은 저마다의 다른 configuration option 들을 가지고 있다. 이 옵션들은 어떻게 display 되는지 혹은 어떻게 동작하는지를 조절하게 된다.

사용 가능한 옵션들은 위젯에 따라 달라진다. 하지만 많은 옵션들에 대해서 일관성을 유지하고 있어서 사용법이 그리 다르지는 않다. 예를 들면 button 과 label 위젯에는 "text" 라는 옵션이 있는데, display 되는 Text 를 조절하게 된다. 하지만 scrollbar 위젯에는 "text" 옵션이 없다(필요가 없으므로). 같은 이유로 "button" 위젯에는 "command" 라는 옵션이 있는 것에 반해, label 위젯에는 해당 옵션이 존재하지 않는다.

옵션 설정은 최초 위젯 생성시에 지정이 가능하며, 생성 이후에도 일부 예외를 제외하고는 대부분 변경이 가능하다. 어떤 옵션들이 사용가능한지 정확히 알지 못하는 경우에는 가능한 옵션이 어떤 것들이 있는지 물어볼 수도 있다. <source lang=python> pchero@mywork:~$ python Python 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from Tkinter import * >>> from ttk import * >>> root = Tk() >>> button = Button(root, text="Hello", command="buttonpressed") >>> button.grid() >>> button['text'] 'Hello' >>> button['text'] = "good bye" >>> button.configure("text") ('text', 'text', 'Text', , 'good bye') >>> button.configure() {'cursor': ('cursor', 'cursor', 'Cursor', , ), ... </source>


See also