简体   繁体   English

如何在tkinter中更改标签位置?

[英]How do you change a labels location in tkinter?

How to you put the label in the upper left corner? 如何将标签放在左上角?

from tkinter import *

root = Tk()
root.title('title')
root.resizable(width=False, height=False)
root.geometry('800x500+200+100')
root.configure(background='black')
photo = PhotoImage(file='image.png')
label = Label(root, image=photo)
label.pack()
root.mainloop()

If you just have the one widget you can use pack or grid with arguments: 如果只有一个小部件,则可以使用带有参数的pack或grid:

label.pack(anchor='nw')

or 要么

label.grid(sticky='nw')

If you want to understand how you can build a GUI, I've got a lot out of Thinking in Tkinter 如果您想了解如何构建GUI,我在Tkinter中有很多思考

Then you will always have the helpful effbot pages: The Tkinter Pack Geometry Manager and The Tkinter Grid Geometry Manager . 然后,您将始终获得有用的effbot页面: Tkinter Pack Geometry ManagerTkinter Grid Geometry Manager

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM