Test/Python(20220101~)

Days27. tkinter, *args, **kwargs, GUI

kiostory 2022. 3. 27. 17:48

 

 

import tkinter          #1. import
window = tkinter.Tk()   #2. window 생성 후
#4. 이 둘 사이에 프로그램을 작성한다
window.mainloop()  #3. 윈도우가 떠있게 하고

 

 

import tkinter
window = tkinter.Tk()
window.title("My First GUI Program(20220327) ")
window.minsize(width=500, height=300)
#Label
my_label = tkinter.Label(text="I am a Label", font=("Arial", 24, "bold"))
my_label.pack()  #label이 표현될 위치 등 정보
window.mainloop()

 

 

*pack()

http://tcl.tk/man/tcl8.6/TkCmd/pack.htm

 

pack manual page - Tk Built-In Commands

The arguments consist of the names of one or more content windows followed by pairs of arguments that specify how to manage the content. See THE PACKER ALGORITHM below for details on how the options are used by the packer. The following options are support

tcl.tk

The Packer

The packer is one of Tk’s geometry-management mechanisms. Geometry managers are used to specify the relative positioning of widgets within their container - their mutual master. In contrast to the more cumbersome placer (which is used less commonly, and we do not cover here), the packer takes qualitative relationship specification - above, to the left of, filling, etc - and works everything out to determine the exact placement coordinates for you.

The size of any master widget is determined by the size of the “slave widgets” inside. The packer is used to control where slave widgets appear inside the master into which they are packed. You can pack widgets into frames, and frames into other frames, in order to achieve the kind of layout you desire. Additionally, the arrangement is dynamically adjusted to accommodate incremental changes to the configuration, once it is packed.

Note that widgets do not appear until they have had their geometry specified with a geometry manager. It’s a common early mistake to leave out the geometry specification, and then be surprised when the widget is created but nothing appears. A widget will appear only after it has had, for example, the packer’s pack() method applied to it.

The pack() method can be called with keyword-option/value pairs that control where the widget is to appear within its container, and how it is to behave when the main application window is resized. Here are some examples:

fred.pack()                     # defaults to side = "top"
fred.pack(side="left")
fred.pack(expand=1)

Packer Options

For more extensive information on the packer and the options that it can take, see the man pages and page 183 of John Ousterhout’s book.

anchor

Anchor type. Denotes where the packer is to place each slave in its parcel.

expand

Boolean, 0 or 1.

fill

Legal values: 'x', 'y', 'both', 'none'.

ipadx and ipady

A distance - designating internal padding on each side of the slave widget.

padx and pady

A distance - designating external padding on each side of the slave widget.

side

Legal values are: 'left', 'right', 'top', 'bottom'.