
上QQ阅读APP看书,第一时间看更新
2-4 Widget的共同属性Anchor
Anchor其实是指标签文字在标签区域输出位置的设置,在默认情况下,Widget控件是上下与左右都居中对齐,可以参考程序实例ch2_4.py的执行结果。也可以使用anchor选项设定Widget控件的对齐,如右图所示。

程序实例ch2_5.py:使用anchor选项重新设计程序实例ch2_4.py,让字符串从标签区间左上角位置开始输出。

执行结果

程序实例ch2_6.py:重新设计程序实例ch2_5.py,让字符串在标签右下方输出。

执行结果

注 anchor的参数设置也可以使用内建大写常数,例如,nw使用NW、n使用N、ne使用NE、w使用W、center使用CENTER、e使用E、sw使用SW、s使用 S、se使用SE。当程序使用大写常数时,可以省略字符串的双引号。
程序实例ch2_6_1.py:使用大写常数重新设计程序实例ch2_6.py。

执行结果 与程序实例ch2_6.py相同。