Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the Python system file?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

The main content of this article is to explain "what are Python system files". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what is a Python system file?"

So-called Python system files: when you write programs in Python, you don't have to think about low-level details such as how to manage the memory used by your programs.

We were surprised to find that the window became smaller, but there was an extra line of words in it. It is smaller because there is already something in the window, and python's Tkinter is very smart and can automatically scale according to the content. Instead of manually specifying absolute coordinates, as with traditional windows programs. For label, it is just a variable. But this variable represents a label, that is, that line of words.

This label is created with Label, and the parameter root of Label indicates that the control is a member of the root main window, or a child window. Label ['text'] means to set the text attribute of the tag to' be on your own', which means text content.

Label.pack is as confusing as root.mainloop, but it is just as profound. You can now simply understand the function of showing label, because if you remove the pack, you can't see anything. In fact, pack is related to the layout and layout of the control.

Just reset the label text. This completes the processing of an event message. if it is written in C, it needs to be longer and more difficult to understand. In addition, are you surprised that the variable label appears in on_click? Obviously, the variable label is not defined before on_click. If I write a program like this in C, the compiler will surely tell me that something is wrong. How does the Python system file know that the variable label exists and does not report it incorrectly?

In fact, when you write Python system files, you don't need to know whether they exist at all, just find label at run time. On the other hand, the context of the run is related through time rather than the relationship between the front and back lines of the code. Here, because label = Label (root) precedes on_click execution, label is a defined variable when on_click executes. What if there is no definition? Then the report is wrong.

From Tkinter import * def on_click (): label ['text'] =' no way out' root = Tk (className='bitunion') label = Label (root) label ['text'] =' be on your own' label.pack () button = Button (root) button ['text'] =' change it' button ['command'] = on_click button.pack () root.mainloop ()

This is more complicated. There is a StringVar in it. This represents a string, but it is different from a normal string. Generally speaking, the string of 'dfsdf'' is immutable. You can only specify the variable as a different string, but the content of the string itself is immutable. StringVar is a variable string.

So use the Python system file to set and get its contents. The main reason is that entry (single-line input box) requires such a property to set and receive the contents of its input box. You may not be used to it at first, but you will find it convenient to use too much, because as long as you use this variable text, you can always get the contents of the current input box.

At this point, I believe that you have a deeper understanding of "what is the Python system file?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report