Hello, World--tkinter code description

Source: Internet
Author: User
Tags pack

To begin, we will first import the Tkinter module. It contains all the classes and functions required by the TK Toolkit and what it needs, and in general, you can import all of the Tkinter's properties and methods directly into your module's namespace:

From Tkinter Import *
      

Initialization Tkinter You must first create a TK root component. You only need to do this one time in each program, and you must first be created before other components are created.

root = Tk ()
      

Next, we create a label component as a child part of the root window:

W = Label (Root, text= "Hello, world!") W.pack ()
      

A Label component can display any text, icon, or picture. Here, we use the text option to specify the text to display. We then call the pack method of the component to tell it to set the appropriate area to display the text and display it. After all this work, We also specify the Tkinter event loop::

Root.mainloop ()
      

The program will stay on the event loop until we close the window. Event loops are used not only to handle user events (such as mouse clicks and keystrokes) or window system events (such as redrawing Windows and window configuration information), but also to handle tkinter operations queues, which are both geometry management (Pack method queues) and display updates. . This also means that the application window will not be displayed before the main loop (main loop).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.