2019.09.03
tkinter.Label
LINKAGE
http://tmml.sourceforge.net/doc/tk/label.html
STANDARD OPTIONS
>>> text
显示在label上的文字
>>>font
显示在label上文字的字体格式,主要有三种:Courier 、Times 、Helvetica
>>>foreground
可以缩略为fg,表示字体颜色
>>>background
可以缩略为bg,表示背景颜色
>>>underline
用于指定第N个字符有下划线,N从0开始。
>>>image
label中可以显示图片,其中,图片必须用tkinter.PhotoImage(file='path')打开(图片必须是gif或ppm/pgm格式),然后赋值给label['image']。下面代码展示的是label中只有图片没有文字。
logo = tk.PhotoImage(file=r"time.gif")
label_image = tk.Label(root)
label_image['image'] = logo
>>>compound
如果label中既有文字也有图片,compound可以规定图片的位置——上、下、左、右、居中,则文字就处于与图片相对的位置。比如,compound = 'left',说明图片在左边,文字在右边;compound = ‘top’,说明图片在上面,文字在下面。
>>>justify
如果text中文字有多行,可以指定文字对齐格式——左对齐、右对齐、居中对齐,对应的参数分别为"left","right","center"。
下面举出两个例子:
举例1中,justify=left,文字左对齐;compound=center,图片处于中间,并且处于底层,上面是文字。
import tkinter as tk
root = tk.Tk()
root.title = 'Python GUI'
logo = tk.PhotoImage(file=r"time.gif")
explanation = '''
The "justify" parameter can be used to justify a text on the LEFT, RIGHT or CENTER. padx ca