introduction of Tkinter and a simple tutorial
Tkinter is a standard GUI library for Python. Python uses Tkinter to quickly create GUI applications.
Because Tkinter is built into the Python installation package, as long as the installation of Python can import Tkinter library, and IDLE is also written with Tkinter, for a simple graphical interface tkinter or can handle it well.
Note: The python3.x version uses a library name of Tkinter, that is, the first letter T is lowercase.
Import Tkinter
Create a GUI program
1, Import Tkinter module
2. Creating controls
3, specify the master of this control, that is, the control belongs to which
4, tell GM (geometry manager) There is a control generated.
Example Examples:
Tkinter Components
Tkinter provides a variety of controls, such as buttons, labels, and text boxes, used in a GUI application. These controls are often referred to as controls or parts.
There are currently 15 kinds of tkinter components. We present these parts as well as a brief introduction in the following table:
Standard Properties
Standard properties are common properties of all controls, such as size, font, color, and so on.
Geometry Management
The Tkinter control has a specific geometry state management method that manages the entire control area organization, which is the Tkinter exposed Geometry Management class: Package, grid, location
The realization Code of the individuality signature
This code run environment is python2.7
#-*-Coding:utf-8-*-from tkinter import * # python 3 is tkinter import tkmessagebox import requests import re from PiL Import Image def download (): Start_url = ' http://www.uustv.com/' name = Entry.get (). Encode (' utf-8 ') if not n Ame:tkMessageBox.showinfo (' Hint ', ' please enter name redesign. ') return data = {' word ': name, ' sizes ': ' Fonts ', ' ' Jfcs.ttf ': ' Fontcolo ' R ': ' #000000 '} result = Requests.post (Start_url, data=data). Content reg = ' <div class= ' tu ' > </div> ' Img_url = Start_url + re.findall (reg, result) [0] response = requests.get (Img_url). Content #
Downloads the generated signature picture to local with open (' {}.gif '. Format (Name.decode) (' Utf-8 '). Encode (' GBK ')), ' WB ' as F:f.write (response)
Try:im = Image.open (' {}.gif '. Format (Name.decode (' utf-8 '). Encode (' GBK ')) Im.show () except: print ' Open it yourself. ' root = Tk () root.title (' Personalized signature design ') root.geometry (' +800+300 ') # Setup window appears on screenThe position above the screen Label (root, text= ' name ', (' Microsoft Jas ',). "Grid () # Layout method do not mix entry = entry (' Microsoft Jas ',") Entry.grid (row= 0, column=1) button = button (root, text= ' design signature '), (' Microsoft Ya-black ', '), width= ', Height=1, command=download) Button.grid (RO W=1, Column=1) Root.mainloop ()
iii. Results of Operation