My_w.mainloop() To manage layout, read more on grid() →Ībove code will open both the windows ( parent and child ) at the beginning. L1 = tk.Label(my_w_child, textvariable=my_str1 ) My_w_child.title("my_str1 = tk.StringVar() My_w_child.geometry("200x200") # Size of the window L1 = tk.Label(my_w, textvariable=my_str ) My_w.geometry("200x200") # Size of the window Here is one sample code to create two windows from starting. ![]() #True is at the top of all windows False normally shows that two windows that are topped at the same time are at the same level (can cover each other), but they can cover windows that are not set to be topped at the same time.Tkinter Toplevel to open child window on button click and to close child window from parent & child #Set the background color, which can be English name or hexadecimal color. It must be in Icon files with suffix ICO are placed in the same directory. #Set the size, length and width of the window to 300x300, and the position where it appears is + 150 + 150 from the upper left corner of the window See the following example of the advanced version: In object-oriented programming language, it is encapsulated into classes. Usually, if you want to write a relatively large program, you should first encapsulate the code. The development of GUI program will have a completely different feeling from the previous development experience. You will have a profound experience in the later study. It doesn’t matter if you don’t understand now. It means that once you enter the main event cycle, Tkinter is in charge of everything. If there is a while, it will be updated every time you click, so we must have a loop.Īll window files must have a similar mainloop function. ![]() Mainloop is equivalent to a large while loop. If there is no mainloop, it is a static root, and the value passed in will not have a loop. #Note that the window will not be displayed at this timeĮxecute the program, as shown in the figure.īecause loop means loop, root Mainloop will make the root refresh constantly. Then the pack () method of the Label component is invoked to automatically adjust the size of the component itself. Label (root, text = "my first Tkinter window!") #Here we let it display the specified text #The label component can display text, icons or pictures #Add a label component, which is one of the most commonly used components in Gui programs. #Sets the title bar of the main window object #Create a main window to hold the whole GUI program For example, idle is designed with Tkinter, so you can directly import Tkinter module: In this demand, Tkinter is competent enough! You can not only use it yourself, but also share it with others. Using python, you can use it as a flexible tool rather than as the main development language, So in the work, you need to make a small tool, which must have an interface. ![]() Python, as a script language or a glue language, generally does not use it to develop complex desktop applications. Second, it comes with its own library, which can be used at any time without downloading and installing. ![]() It is necessary to develop a small image window.įor people with a little GUI programming experience, Python’s Tkinter interface library is very simple. For example, if we want to develop a calculator, if it is just a black window for keyboard input and output, it is useless for user experience. We can use GUI to realize many intuitive functions. Tkinter is a GUI interface that comes with Python and can be edited. As a specific GUI interface of python, Tkinter is an image window.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |