【问题标题】:Tkinter label text positionTkinter 标签文本位置
【发布时间】: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:' 根据 ': ' 后面的数字在窗口左右移动。

【问题讨论】:

标签: python-3.x tkinter tkinter-canvas


【解决方案1】:

尝试将justify='left' 参数添加到标签:

s = Frame(self, width=150, height=20)
s.pack_propagate(0)
s.place(x=0,y=680)
v = Label(s, fg='black',anchor='w', justify='left')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-15
    • 1970-01-01
    • 2017-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多