设置TKinter标签的位置? [英] Setting the position of TKinter labels?

查看:80
本文介绍了设置TKinter标签的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个程序,我在窗口的左下角和右下角放置了一个标签.我的代码如下:

I am trying to make a program, where I place a label in the bottom left and bottom right corners of my window. My code is as follows:

root = Tk()
root.geometry("1000x250")
var = StringVar()
label = Label( root, textvariable=var)

var.set("Hey!? How are you doing?")
label.place(x=20, y=60)
label.pack()
root.configure(background='lightyellow')
root.mainloop()

出于某种原因,当我这样做时,标签根本没有改变.我是 TKinter 的新手,所以我不知道该怎么做.任何帮助,将不胜感激.

For some reason, when I do so, the label does not change at all. I am new to TKinter, so I am not sure how to go about this. Any help would be appreciated.

推荐答案

如果可能的话,我会使用 .grid.将标签放在左下角和右下角的单元格中.使用 .place:

I would use .grid if at all possible. Put labels in lower left and lower right cells. Using .place:

import tkinter as tk
root = tk.Tk()
root.geometry("1000x250")
ll = tk.Label(root, text='lower left')
lr = tk.Label(root, text='lower right')
##ll.place(x=0, y=250, anchor='sw')
##lr.place(x=1000, y=250, anchor='se')
ll.place(relx=0.0, rely=1.0, anchor='sw')
lr.place(relx=1.0, rely=1.0, anchor='se')
#root.mainloop()

使用绝对 x,y 放置,如果调整窗口大小,标签不会移动.在相对位置上,它们确实如此.

With absolute x,y placing, labels do not move if window is resized. With relative placing, they do.

这篇关于设置TKinter标签的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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