In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to use Python Tkinter". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The official GUI toolkit, Tkinter (which is where IDLE was developed).
Tkinter is the standard GUI library of Python, which is actually based on Tk technology. On most Unix platforms and Windows systems
Both are available.
As a python-specific GUI interface, is an image window, tkinter is python's own, can be edited GUI interface, I
We can use GUI to achieve many intuitive functions, such as if you want to develop a calculator, if it is only a black window for keyboard input and output
Mouth, is useless user experience. It is necessary to develop a small graphic window.
For people with a little experience in GUI programming, Python's Tkinter interface library is very simple. Python has a large number of GUI libraries, so choose
Tkinter, the first is the simplest, the second is to bring its own library, do not need to download and install, at any time to use, the third is to proceed from the requirements, Python as a
A scripting language, or a glue language, is generally not used to develop complex desktop applications, and it does not have this advantage.
With Python, you can use it as a flexible tool rather than as the main development language, so in your work, you need to make a
Gadgets, certainly need to have an interface, not only for their own use, but also to share the use of others, in this case, Tkinter is competent enough
Yes!
Tkinter is the default GUI library for Python. For example, IDLE is designed with Tkinter, so you can import the Tkinter module directly:
The initial experience of Tkinter
Let's start with the simplest example:
Import tkinter import tkinter as tk # create a main window for the entire GUI program root = tk.Tk () # set the title bar of the main window object root.title ("First Demo") # add a Label component, the Label component is one of the most commonly used components in GUI programs. # Label components can display text, icons or pictures # here we let it display the specified text theLabel = tk.Label (root, text= "my first tkinter window!") # and then call the pack () method of the Label component to automatically resize the component itself theLabel.pack () # Note that the window still does not display at this time. # unless the following code is executed! Root.mainloop ()
Execute the program as shown in the figure.
Because loop means loop, root.mainloop will make root refresh constantly. If there is no mainloop, it is a static root. The value passed in will not have a loop. Mainloop is equivalent to a large while loop. There is a while, which will be updated every time you click, so we must have a loop.
All window files must have similar mainloop functions, and mainloop is the key to window files.
It means that once you enter the main event loop, Tkinter is in charge. It doesn't matter if you don't understand now, you will have profound experience in later study. The development of GUI programs will feel very different from previous development experience.
Usually if you want to write a larger program, you should package the code first. In object-oriented programming languages, it is encapsulated into classes. Take a look at the following example of an advanced version:
Import tkinter as tk def create_button (root): # create a button component # fg is an abbreviation for foreground, which means setting the foreground color say_hello = tk.Button (root, text=' say hello', fg='blue' Command=eat) say_hello.pack () return root def eat (): print ('have you eaten today?') root = tk.Tk () app = create_button (root) root.mainloop () "how to use Python Tkinter" ends here Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.