Python supports a variety of third-party libraries for graphical interfaces, including:
wxWidgets
Qt
GTK
Tkinter: The Tkinter module (Tk interface) is an interface to Python's standard Tk GUI toolkit. Tk and Tkinter work on most Unix platforms, but can also be used on Windows and Macintosh. Subsequent versions of Tk8.0 implement a native windowing style that works well on most platforms. Tk8.0 can be used on most Unix platforms, as well as Windows and Macintosh.
wxPython: wxPython is an open source software , is a set of Python language excellent GUI graphics library , allows Python programmers to easily create a complete , full-featured GUI user interface .
Jython: Jython programs integrate seamlessly with Java. Jython uses Java's modules, except for a few standard modules, and has almost all of the standard Python modules that do not depend on C. For example, a Jython user interface will use Swing, AWT, or SWT. For example, a Jython user interface will use Swing, AWT, or SWT. Jython can be dynamically or statically compiled into Java bytecode.
Tkinter
Let's sort out the concepts:
The Python code we write calls the built-in Tkinter, which encapsulates the interface to access Tk;
Tk is a graphics library that supports multiple operating systems and is developed using the Tcl language;
Tk will call the native GUI interface provided by the operating system to complete the final GUI.
So, our code only needs to call the interface provided by Tkinter.
In the GUI, each Button, Label, input box, etc., is a Widget. Frame is a Widget that can hold other Widgets, and all the Widgets combined are a tree.
The pack() method adds the Widget to the parent container and implements the layout. pack() is the simplest layout, and grid() enables more complex layouts.
Tkinter
Create a GUI program
1. Import Tkinter module
2、Create control
3、Specify the master of the control, that is, the control belongs to a
4. Tell the GM(geometry manager) that a control has been generated.
Example:
#!/usr/bin/python # -*- coding: UTF-8 -*- import Tkinter top = () # Into the message loop ()
subassemblies
Tkinter offers a variety of controls such as buttons, labels and text boxes for use in a GUI application. These controls are often referred to as controls or widgets.
There are currently 15 Tkinter parts available. We present these parts along with a short introduction in the table below:
a control (e.g. button, text box etc) (computing) | descriptive |
---|---|
Button | Button control; displays buttons in the program. |
Canvas | Canvas control; displays graphic elements such as lines or text |
Checkbutton | Multi-Checkbox control; used to provide multiple checkboxes in a program |
Entry | Input control; used to display simple text content |
Frame | Frame control; displays a rectangular area on the screen, mostly used as a container ***************************** |
Label | Label control; can display text and bitmap |
Listbox | Listbox control; the widget in the Listbox window is used to display a list of strings to the user |
Menubutton | Menu button control due to displaying menu items. |
Menu | Menu control; displays menu bars, drop-down menus and pop-up menus. |
Message | Message control; used to display multiple lines of text, similar to a label. |
Radiobutton | Radio Button control; displays a radio button state. |
Scale | Range control; displays a numeric scale that defines a range of numeric intervals for the output |
Scrollbar | Scroll bar control, used when the content exceeds the visualization area, such as a list box . |
Text | Text control; used to display multi-line text |
Toplevel | Container control; used to provide a single dialog box, similar to Frame. |
Spinbox | Input control; similar to Entry, but you can specify a range of values for the input. |
PanedWindow | PanedWindow is a window layout management plugin that can contain one or more child controls. |
LabelFrame | labelframe is a simple container control. It is often used with complex window layouts. |
tkMessageBox | Used to display your application's message box. |
standard property
Standard properties are properties that are common to all controls, such as size, font and color, etc.
causality | descriptive |
Dimension | The size of the control; |
Color | The control color; |
Font | Control fonts; |
Anchor | Anchors; |
Relief | control style; |
Bitmap | Bitmap; |
Cursor | Cursor; |
Geometric management
Tkinter controls have specific geometry management methods that govern the organization of the entire control area. The following are the geometry management classes exposed by Tkinter: package, grid, position
geometric method | descriptive |
pack() | Packaging; |
grid() | Grid; |
place() | Location; |
#!/usr/bin/env python import os from time import sleep from Tkinter import * class DirList(object): def __init__(self, initdir=None): = Tk() = Label(, text='Directory Lister v1.2') () =StringVar() = Label(, fg='blue', font=('Helvetica', 12, 'bold')) () = Frame() = Scrollbar() (side=RIGHT, fill=Y) = Listbox(, height=15, width=50, yscrollcommand=) ('<Double-1>', ) (command=) (side=LEFT, fill=BOTH) () = Entry(, width=50, textvariable=) ('<Return>', ) () = Frame() = Button(, text='Clear', command=, activeforeground='white', activebackground='blue') = Button(, text='List Directory', command=, activeforeground='white', activebackground='green') = Button(, text='Quit', command=, activeforeground='white', activebackground='red') (side=LEFT) (side=LEFT) (side=LEFT) () if initdir: () () def clrdir(self, ev=None): ('') def setdirandgo(self, ev=None): = () (selectbackground='red') check = (()) if not check: check = (check) () def dols(self, ev=None): error = '' tdir = () if not tdir: tdir = if not (tdir): error = tdir + ': no such file' elif not (tdir): error = tdir + ': not a directory' if error: (error) () sleep(2) if not (hasattr(self, 'last') \ and ): = () ( selectbackground='LightSkyBlue') () return ( 'FETCHING DIRECTORY CONTENTS...') () dirlist = (tdir) () (tdir) (text=()) (0, END) (END, ) (END, ) for eachFile in dirlist: (END, eachFile) () ( selectbackground='LightSkyBlue') def main(): d = DirList() mainloop() if __name__ == '__main__': main()
Above this python implementation of GUI (graphical user interface) programming details is all I have shared with you, I hope to be able to give you a reference, but also hope that you support me more.