Tkinter Label Widget: Display Text & Images in Python GUI
The `Label` widget in tkinter is used to display text or an image on the screen. It can be used to provide information or instructions to the user.
Here is an example of creating a label in tkinter:
import tkinter as tk
root = tk.Tk()
label = tk.Label(root, text="Hello, World!")
label.pack()
root.mainloop()
In this example, we create a label widget with the text "Hello, World!" and then use the `pack` method to add it to the root window. The `mainloop` method is used to start the tkinter event loop.
We can also customize the label's appearance by passing various options to the `Label` constructor. Here is an example that sets the font, background color, and foreground color of the label:
import tkinter as tk
root = tk.Tk()
label = tk.Label(root, text="Hello, World!", font=("Arial", 12), bg="blue", fg="white")
label.pack()
root.mainloop()
In this example, we set the font to Arial with a size of 12, the background color to blue, and the foreground color to white.
原文地址: http://www.cveoy.top/t/topic/hSdw 著作权归作者所有。请勿转载和采集!