Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the use of Label in python

Shulou Source: shulou.com Published: 2022-06-03 15:33:50 10月02日 Update

This article mainly introduces the use of Label in python, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Description

1. Label is one of the PythonTkinter tag components, which mainly displays the text and images in the specified window.

2. Inherit the Label of Widget class.

3. Only displayed text and images can be used to display one or more lines of text, and users are not allowed to modify them.

Grammar

W = Label (master,option)

Master: parent container

Options: optional, set attributes of tags in the form of key-value pairs, separated by semicolons

Example

From tkinter import * class Application (Frame): def _ _ init__ (self,master=None): # super () represents the definition of the parent class Instead of the parent object super (). _ init__ (master) self.master = master self.pack () # self.createwidget () self.createWidget () def createwidget (self): self.but1 = Button (self) self.but1 ["text"] = "add" self.but1.pack () self.but1 ["command"] = Self.addinfo def addinfo (self): messagebox.showinfo ("prompt" "added successfully") def createWidget (self): self.lab1 = Label (self,text= "this is tag 1", width = 10 self.lab2 height = 2 white bg = "pink", fg= "white") self.lab1.pack () self.lab2 = Label (self,text= "this is tag 2", width = 10 camera height = 2 Label bg = "orange", fg= "black", font= ("boldface") 30) self.lab2.pack () global photo photo = PhotoImage (file= "heart.gif") self.lab3 = Label (self,image = photo) self.lab3.pack () root = Tk () root.geometry ("400x200+200+300") root.title ("MyfirstAPP") app = Application (master=root) root.mainloop () Thank you for reading this article carefully I hope the article "what is the use of Label in python" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Tags articles text images this is success one line representative value interest semicolon at the same time instance container object attribute form more friends user Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi macOS vpn Xiaomi Huawei