【发布时间】:2017-03-27 22:01:15
【问题描述】:
我以为我知道答案的简单问题。你是怎么做到的,所以文本在标签的左侧排成一行?我的窗口上有两个标签,每当我移动鼠标时,我都会更新标签中的文本,它显示鼠标的 x-y 坐标(x 位置 = ****** 和 y 位置 = ***** *)。问题是文本在我身上弹跳,这表明它没有在标签的左侧排列。我试过 anchor = 'w' 但这不起作用。当我在屏幕上移动鼠标时, text(x position = ), x position = 仍然会跳动。
编辑:
这是用来创建窗口的
s = Frame(self, width=150, height=20)
s.pack_propagate(0)
s.place(x=0,y=680)
v = Label(s, fg='black',anchor='w')
这是用来更新窗口的
v.config(text = "x-position: " + str(px),anchor='w')
s 和 v 设置为全局
该代码不会锚定窗口左侧的文本。 'x-position:' 根据 ': ' 后面的数字在窗口左右移动。
【问题讨论】:
-
anchor-'w'是让文本在标签中左对齐的方式。请给我们看一些代码。阅读并遵循此处的建议:How to create a Minimal, Complete, and Verifiable example
标签: python-3.x tkinter tkinter-canvas