Home>Article>Backend Development> Is tkinter built-in with python?
Tkinter module (Tk interface) is the interface of Python's standard Tk GUI toolkit. Tk and Tkinter can be used on most Unix platforms, as well as on Windows and Macintosh systems. Subsequent versions of Tk8.0 can implement native window styles and run well on most platforms.
Tkinter is the standard GUI library for Python. Python uses Tkinter to quickly create GUI applications.
Since Tkinter is built into the python installation package, you can use import to import the Tkinter library after installing Python, and IDLE is also written in Tkinter. Tkinter can still handle the simple graphical interface easily.
Note:The library name used by the Python3.x version is tkinter, that is, the first letter T is lowercase.
import tkinter
How to create a GUI program?
Steps:
1. Import the Tkinter module
2. Create the control
3. Specify The master of this control, that is, which
# this control belongs to. 4. Tell GM (geometry manager) that a control has been generated.
Example 1:
#!/usr/bin/python # -*- coding: UTF-8 -*- import Tkinter top = Tkinter.Tk() # 进入消息循环 top.mainloop()
The execution result of the above code is as follows:
Example 2:
#!/usr/bin/python # -*- coding: UTF-8 -*- from Tkinter import * # 导入 Tkinter 库 root = Tk() # 创建窗口对象的背景色 # 创建两个列表 li = ['C','python','php','html','SQL','java'] movie = ['CSS','jQuery','Bootstrap'] listb = Listbox(root) # 创建两个列表组件 listb2 = Listbox(root) for item in li: # 第一个小部件插入数据 listb.insert(0,item) for item in movie: # 第二个小部件插入数据 listb2.insert(0,item) listb.pack() # 将小部件放置到主窗口中 listb2.pack() root.mainloop() # 进入消息循环
The execution result of the above code is as follows:
The above is the detailed content of Is tkinter built-in with python?. For more information, please follow other related articles on the PHP Chinese website!