Introduction to Python system files

Source: Internet
Author: User

For users and scholars who first came into contact with Python system files, it is very important to understand the concept of Python system files. let's first talk about what is a Python system file, the so-called Python system file: when writing a program in Python, you do not need to consider the underlying details such as how to manage the memory used by your program.

We are surprised to find that the window has become smaller, but there is a line more. This is because something has been put in the window. python Tkinter is very intelligent and can be scaled automatically based on the content. You don't need to manually specify the absolute coordinates like the traditional windows program. Label is a variable. However, this variable represents a tag, that is, a line of words.

The label is created using the Label, and the Label parameter is root, indicating that the control is a member control of the root main window, or a child window. Label ['text'] indicates that the text attribute of this label is 'Be on your own ', that is, the text content.

  • Reveal the secrets of Python features
  • How to compile Python code
  • How to Develop Python correctly
  • How to build a Python development environment correctly
  • Notes for getting started with the Python Module

Label. pack is as confusing as root. mainloop, but profound as it is. Now, you can simply understand the label display function. Because you remove the pack, you will not be able to see anything. In fact, pack is related to the layout and layout of controls.

Just reset the text of the label. This completes the processing of an event message. If you use C for writing, you need to write a code that is longer and harder to understand. In addition, are you surprised to see the label variable in on_click? The label variable is not defined before on_click. If I write a program like this in C, the compiler will tell me what went wrong. But how does the Python System File know that the label variable exists and no error is reported?

In fact, you don't need to know whether the Python system file exists when you write it. You just need to find the label when running it. The frontend and backend relationships are associated by time, rather than the relationship between the Code going forward and going forward. Here, because label = Label (root) is executed before on_click, when on_click is executed, label is a defined variable. What if there is no definition? Report the error.

 
 
  1. from Tkinter import *  
  2. def on_click():  
  3.     label['text'] = 'no way out'  
  4. root = Tk(className='bitunion')  
  5. label = Label(root)  
  6. label['text'] = 'be on your own'  
  7. label.pack()  
  8. button = Button(root)  
  9. button['text'] = 'change it'  
  10. button['command'] = on_click  
  11. button.pack()  
  12. root.mainloop() 

This is complicated. There is a StringVar in it. This represents a string, but it is different from a general string. Generally, the 'dfsdf 'string is unchangeable. You can only specify variables as different strings, but the content of the string itself cannot be changed. StringVar is a variable string.

Therefore, you can use a Python system file to set and obtain its content. This attribute is required to set and receive the content of the input box. You may not get used to it at the beginning, but it will be very convenient to use the variable text to get the content of the current input box.

When you can fully understand this example, you are getting started. But there is still some distance from writing a window application. The lack of richer control and Event Response processing capabilities, as well as reasonable layout capabilities. Next time.

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.