1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#! /usr/bin/env python
#coding=utf-8
from
Tkinter
import
*
class
LabelDemo( Frame ):
"""Demonstrate Labels"""
def
__init__(
self
):
"""Create three Labels and pack them"""
Frame.__init__(
self
)
# initializes Frame instance
# frame fills all available space
self
.pack( expand
=
YES, fill
=
BOTH )
self
.master.title(
"Labels"
)
self
.Label1
=
Label(
self
, text
=
"Label with text"
)
# resize frame to accommodate Label
self
.Label1.pack()
self
.Label2
=
Label(
self
,
text
=
"Labels with text and a bitmap"
)
# insert Label against left side of frame
self
.Label2.pack( side
=
LEFT )
# using default bitmap image as label
self
.Label3
=
Label(
self
, bitmap
=
"warning"
)
self
.Label3.pack( side
=
LEFT )
def
main():
LabelDemo().mainloop()
# starts event loop
if
__name__
=
=
"__main__"
:
main()
|
注意一下,添加组件的时候,下面这一行代码还是不能少的,笔者也是刚刚接触,说错了大家别喷。
|
如果取消这一行的话,其他的组件不能显示。