''''Tkinter Tutorial Canvas Chapter (4)'''
'''22. Draw an arc'''
# -*- coding: cp936 -*-
# Create an ARC
from Tkinter import * root = Tk()
# Create a Canvas and set its background color to white
cv = Canvas(root,bg = 'white') cv.create_arc((10,10,110,110),) cv.pack() root.mainloop()
# Create an ARC using default parameters, the result is a 90-degree sector
'''23. Set the arc style'''
# -*- coding: cp936 -*-
# Create create_arc.
from Tkinter import * root = Tk()
# Create a Canvas , set its background color to white
cv = Canvas(root,bg = 'white') d = {1:PIESLICE,2:CHORD,3:ARC} for i in d: cv.create_arc((10,10 + 60*i,110,110 + 60*i),style = d[i]) print i,d[i], cv.pack() root.mainloop()
# Use three styles to create fan, bow and arc shapes respectively
'''24. Set the angle of the arc'''
# -*- coding: cp936 -*-
# Use start/extent to specify the starting angle Create a Canvas with the offset angle
from Tkinter import * root = Tk()
# and set its background color to white
cv = Canvas(root,bg = 'white') d = {1:PIESLICE,2:CHORD,3:ARC} for i in d: cv.create_arc( (10,10 + 60*i,110,110 + 60*i),
style = d [i], #Specify style
start = 30, #Specify starting angle
extent = 30 #Specify angle offset
)
cv.pack()
root.mainloop()
# Use three styles, start specifies the start Angle; extent specifies angle offset
'''25. Draw bitmap'''
# -*- coding: cp936 -*-
# Use bitmap to create a bitmap create_bitmap
from Tkinter import *
root = Tk()
# Create A Canvas, set its background color to white
cv = Canvas(root,bg = 'white') d = {1:'error',2:'info',3:'question',4:'hourglass'} for i in d: cv.create_bitmap((20*i,20*i),bitmap = d[i]) cv.pack() root.mainloop()
# Use the bitmap attribute to specify the name of the bitmap. The first parameter of this function is a point (x, y ) specifies the upper left position of the bitmap storage location.
'''26. Draw GIF image'''
# -*- coding: cp936 -*-
# Create gif image create_image
from Tkinter import *
root = Tk()
# Create a Canvas and set its background color to white
cv = Canvas(root,bg = 'white') img = PhotoImage(file = 'c:/python.gif') cv.create_image((150,150),image = img) cv.pack() root.mainloop()
# First use PhotoImage to create a GIF image, and then set the image attribute to the newly created img
'''27. Draw Line'''
# -*- coding: cp936 -*-
# Create a straight line with an arrow create_line
from Tkinter import *
root = Tk()
# Create a Canvas and set its background color to white
cv = Canvas(root,bg = 'white') d = [(0,'none'),(1,'first'),(2,'last'),(3,'both')] for i in d: cv.create_line( (10,10 + i[0]*20,110,110+ i[0] * 20), # 设置直线的起始、终点 arrow = i[1], # 设置直线是否使用箭头 arrowshape = '40 40 10' # 设置箭头的形状(填充长度,箭头长度,箭头宽度 ) cv.pack() root.mainloop()
# Use the arrow attribute to control whether to display arrows
'''28. The joinstyle attribute of a straight line'''
# -*- coding: cp936 -* -
# Create a straight line, use the joinstyle attribute
from Tkinter import *
root = Tk()
# Create a Canvas and set its background color to white
cv = Canvas(root,bg = 'white') d = [(0,'none','bevel'),(1,'first','miter'),(2,'last','round'),(3,'both','round')] for i in d: cv.create_line( (10,10 + i[0]*20,110,110+ i[0] * 20), # 设置直线的起始、终点 arrow = i[1], # 设置直线是否使用箭头 arrowshape = '8 10 3', # 设置箭头的形状(填充长度,箭头长度,箭头宽度 joinstyle = i[2], ) cv.pack() root.mainloop()
# Set the joinstyle attribute of the straight line to bevel/miter/round respectively, and test it Effect.
'''29. Draw an ellipse'''
# -*- coding: cp936 -*-
# Draw an ellipse , use the create_oval attribute
from Tkinter import *
root = Tk()
# to create a Canvas and set its background color to White
cv = Canvas(root,bg = 'white')
# Create an ellipse with a length of 200 and a width of 100
cv.create_oval((10,10,210,110),fill = 'red') cv.pack() root.mainloop()
# specifies the length and width of the ellipse, a circle is a special case where the length and width are equal.
'''30. Create a polygon'''
# -*- coding: cp936 -*-
# Create a polygon (Triangle)
from Tkinter import *
root = Tk()
# Draw a Canvas and set its background color to white
cv = Canvas(root,bg = 'white')
# Create a right triangle
cv.create_polygon((10,10,10,200,100,200),fill = 'red') cv.pack() root.mainloop()
# Specify the coordinates of three points. The coordinates of the three points must meet the definition of a triangle.
'''31. Modify graphics'''
# -*- coding: cp936 -*-
# Create polygons create_ploygon (triangle)
from Tkinter import *
root = Tk()
# Create a Canvas and set its background color to White
cv = Canvas(root,bg = 'white')
# Create a right triangle
cv.create_polygon((10,10,10,200,100,200), #smooth = True, # 平滑处理,但未找到控制此参数的项 splinesteps = 0, # 不明白是控制什么的??? ) cv.pack() root.mainloop()
# Smooth/splinesteps is used to modify the drawn graphics. I don’t know what other functions these two parameters have.
'''32. Draw text'''
# -*- coding: cp936 -*-
# Use text create_text
from Tkinter import * root = Tk()
# Create a Canvas and set its background color to white
cv = Canvas(root,bg = 'white')
# Create a text object, the default setting is center alignment
cv.create_text((10,10),text = 'Hello Text', anchor = W ) cv.pack() root.mainloop()
# Use anchor to control the position of the text, and use justify to control the alignment
'''33. Select text'''
# -*- coding: cp936 -*-
# Use text create_text
from Tkinter import * root = Tk()
# 创建一个Canvas,设置其背景色为白色
cv = Canvas(root,bg = 'white')
# 创建一个文字对象,默认设置为居中对齐
txt = cv.create_text((10,10),text = 'Hello Text', anchor = W )
# 设置文本的选中起始位置
cv.select_from(txt,2)
# 设置文本的选中结束位置
cv.select_to(txt,5) cv.pack() root.mainloop()
# 使用anchor控制文字的位置,使用justify控制对齐方式
'''34.创建组件'''
# -*- coding: cp936 -*-
# 使用子组件create_window
from Tkinter import * root = Tk()
# 创建一个Canvas,设置其背景色为白色
cv = Canvas(root,bg = 'white')
# 创建一个Button对象,默认设置为居中对齐
def printWindow(): print 'window' bt = Button(cv,text = 'ClickMe',command = printWindow)
#修改button在canvas上的对齐方式
cv.create_window((10,10),window = bt,anchor = W)
# 新创建的line对象与button有重叠
cv.create_line(10,10,20,20)
# 新创建的line不在button之上,即没有重叠
cv.create_line(30,30,100,100) cv.pack() root.mainloop()
# 使用anchor组件在Canvas上的位置,默认情况下为居中对齐,这样使用后其它的item将不能再使用button战胜的那块区域
以上就是Tkinter教程之Canvas篇(4)的内容,更多相关内容请关注PHP中文网(www.php.cn)!

There is no difference between HTML5 and H5, which is the abbreviation of HTML5. 1.HTML5 is the fifth version of HTML, which enhances the multimedia and interactive functions of web pages. 2.H5 is often used to refer to HTML5-based mobile web pages or applications, and is suitable for various mobile devices.

HTML5 is the latest version of the Hypertext Markup Language, standardized by W3C. HTML5 introduces new semantic tags, multimedia support and form enhancements, improving web structure, user experience and SEO effects. HTML5 introduces new semantic tags, such as, ,, etc., to make the web page structure clearer and the SEO effect better. HTML5 supports multimedia elements and no third-party plug-ins are required, improving user experience and loading speed. HTML5 enhances form functions and introduces new input types such as, etc., which improves user experience and form verification efficiency.

How to write clean and efficient HTML5 code? The answer is to avoid common mistakes by semanticizing tags, structured code, performance optimization and avoiding common mistakes. 1. Use semantic tags such as, etc. to improve code readability and SEO effect. 2. Keep the code structured and readable, using appropriate indentation and comments. 3. Optimize performance by reducing unnecessary tags, using CDN and compressing code. 4. Avoid common mistakes, such as the tag not closed, and ensure the validity of the code.

H5 improves web user experience with multimedia support, offline storage and performance optimization. 1) Multimedia support: H5 and elements simplify development and improve user experience. 2) Offline storage: WebStorage and IndexedDB allow offline use to improve the experience. 3) Performance optimization: WebWorkers and elements optimize performance to reduce bandwidth consumption.

HTML5 code consists of tags, elements and attributes: 1. The tag defines the content type and is surrounded by angle brackets, such as. 2. Elements are composed of start tags, contents and end tags, such as contents. 3. Attributes define key-value pairs in the start tag, enhance functions, such as. These are the basic units for building web structure.

HTML5 is a key technology for building modern web pages, providing many new elements and features. 1. HTML5 introduces semantic elements such as, , etc., which enhances web page structure and SEO. 2. Support multimedia elements and embed media without plug-ins. 3. Forms enhance new input types and verification properties, simplifying the verification process. 4. Offer offline and local storage functions to improve web page performance and user experience.

Best practices for H5 code include: 1. Use correct DOCTYPE declarations and character encoding; 2. Use semantic tags; 3. Reduce HTTP requests; 4. Use asynchronous loading; 5. Optimize images. These practices can improve the efficiency, maintainability and user experience of web pages.

Web standards and technologies have evolved from HTML4, CSS2 and simple JavaScript to date and have undergone significant developments. 1) HTML5 introduces APIs such as Canvas and WebStorage, which enhances the complexity and interactivity of web applications. 2) CSS3 adds animation and transition functions to make the page more effective. 3) JavaScript improves development efficiency and code readability through modern syntax of Node.js and ES6, such as arrow functions and classes. These changes have promoted the development of performance optimization and best practices of web applications.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version
Recommended: Win version, supports code prompts!

Atom editor mac version download
The most popular open source editor