'''Tkinter教程之Canvas篇(2)'''
'''9.創建item的tags'''
# -*- coding: cp936 -*-
# tags設定item的tag
# 使用Canvas的方法gettags取得指定item的tags
from Tkinter import * root = Tk()
# 建立一個Canvas,設定其背景色為白色
(rr r1')
cv = Canvas(root,bg = 'white')
rt = cv.create_rectangle(10,10,110,110, tags = 'r1' ) cv.pack() print cv.gettags(rt)
cv.itemconfig(rt,tags = ('r2','r3','r4')) print cv.gettags(rt) root.mainloop()
from Tkinter import * root = Tk()
rt = cv.create_rectangle(10,10,110,110, tags = ('r1','r2','r3') ) cv.pack() cv.create_rectangle(20,20,80,80,tags = 'r3') print cv.find_withtag('r3') root.mainloop()
# 多個控制使用同一個tag
from Tkinter import * root = Tk()
rt = cv.create_rectangle(10,10,110,110, tags = ('r1','r2','r3') ) cv.pack() cv.create_rectangle(20,20,80,80,tags = 'r3')
cv = Canvas(root,bg = 'white')
使用
for item in cv.find_withtag('r3'): cv.itemconfig(item,outline = 'blue') root.mainloop()
from Tkinter import * root = Tk()
# 使用addtag_來向上一個或下一個item添加tag
一個Canvas,設定其背景色為白色
cv = Canvas(root,bg = 'white')
rt1 = cv.create_rectangle( 10,10,110,110, tags = ('r1','r2','r3')) rt2 = cv.create_rectangle( 20,20,80,80, tags = ('s1','s2','s3')) rt3 = cv.create_rectangle( 30,30,70,70, tags = ('y1','y2','y3'))
cv.addtag_above('r4',rt2)
'''14.返回其它item'''
# 使用find_xxxr ,設定其背景色為白色
cv.addtag_below('r5',rt2) for item in [rt1,rt2,rt3]: print cv.gettags(item) cv.pack() root.mainloop()
from Tkinter import * root = Tk()
cv = Canvas(root,bg = 'white')
以上就是Tkinter教程之Canvas篇(2)的內容,更多相關內容請關注PHP中文網(www.php.cn)!