Python tkinter:消息小部件中锚选项的正确值是什么? [英] Python tkinter: What are the correct values for the anchor option in the message widget?

查看:34
本文介绍了Python tkinter:消息小部件中锚选项的正确值是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在通过 http://www.python-course.eu/tkinter_message_widget 学习 tkinter.php

当我使用网站上提供的选项添加锚选项时,我不断收到错误消息.有人告诉我 NE 不存在,但在上面的链接中 NE 作为锚选项给出:

NameError: name 'NE' 未定义

这是我的代码.

导入tkinter根 = tkinter.Tk()message = ("你所做的一切都是微不足道的,"但你这样做很重要.\n"(圣雄甘地)")msg = tkinter.Message(root,text = message,anchor = NE,aspect = 1000,前景='红色',背景='黄色',highlightcolor='green', highlightthickness=0,边框宽度=500)#msg.config(bg='lightgreen', font=('times', 24, 'italic'))msg.pack()tkinter.mainloop()

我也尝试在单引号中输入NE",但没有奏效.

解决方案

值是字符串n"、ne"、e"、se"、s"、sw"、w"、nw"或中心".案例很重要.它们代表罗盘的方向(北、南、东、西)

在您的情况下,您使用的是包含这些值的 tkinter 常量.由于您导入 tkinter 的方式,您必须使用模块名称作为这些常量的前缀.例如,tkinter.NE.

我个人认为使用设置为n"或ne"的常量 NNE 很奇怪.除了在这种情况下有时会引起混淆之外,常量没有任何用处.

这是规范文档:><块引用>

指定小部件中的信息(例如文本或位图)在小部件中的显示方式.必须是 n、ne、e、se、s、sw、w、nw 或中心值之一.例如,nw 表示显示信息,使其左上角位于小部件的左上角.

I have been learning tkinter through http://www.python-course.eu/tkinter_message_widget.php

I keep getting an error when I add the anchor option with the options presented on the site. I am being told that NE does not exist but NE is given as an anchor option in the link above:

NameError: name 'NE' is not defined

Here's my code.

import tkinter

root = tkinter.Tk()
message = ("Whatever you do will be insignificant,"
"but it is very important that you do it.\n"
"(Mahatma Gandhi)")

msg = tkinter.Message(root,text = message, anchor = NE, aspect = 1000,
                      foreground='red', background='yellow', 
                      highlightcolor='green', highlightthickness=0,
                      borderwidth=500)
#msg.config(bg='lightgreen', font=('times', 24, 'italic'))
msg.pack()
tkinter.mainloop()

EDIT: I also tried typing in 'NE' in single quotes and it didn't work.

解决方案

The values are the string literals "n", "ne", "e", "se", "s", "sw", "w", "nw", or "center". Case is important. They represent the directions of the compass (north, south, east, and west)

In your case you're using tkinter constants that contain these values. Because of the way you are importing tkinter, you must prefix these constants with the module name. For example, tkinter.NE.

Personally I think it's odd to use a constant N or NE that is set "n" or "ne". The constant serves no purpose other than to sometimes cause confusion in cases such as this.

Here is the canonical documentation:

Specifies how the information in a widget (e.g. text or a bitmap) is to be displayed in the widget. Must be one of the values n, ne, e, se, s, sw, w, nw, or center. For example, nw means display the information such that its top-left corner is at the top-left corner of the widget.

这篇关于Python tkinter:消息小部件中锚选项的正确值是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆