Buscar

Introdução a Python - Módulo C

Prévia do material em texto

!!""##$$%%&&!!''(())**&&++!!,,%%##--..--++)),,//!!
00++))##&&11$$2233&&!!,,!!''(())**&&++!!44!!556611$$77&&!!88!!
 
 
 
 
 
99::;;++))--##<<!!
 
 
 
==&&..$$>>!!??,, ,,::;;!!
77,, ,,::;;!!""--;;..##$$++--..%%## ##!!
!!
 
 
 
 
 
 
 
 
!
$%&''!4!0?()!'*?9&0+)!
UNIVERSIDADE ESTADUAL PAULISTA 
“JÚLIO DE MESQUITA FILHO”!
" # $ % & ' ( ) * & ! + ! , - $ . & # ! / ! 0 1 ' ( 2 & ! 3 !
$ 4 " # $ 5 % 
 
6 & 7 ( 8 ! 2 + 9 + 4 " ! / ! : % ( , & ! , - $ . & # ! / ! ( # 5 7 , ! / ! " 2 . + ! 7 & 2 $ 5 " % + ! 2
+;<=>=? !"#$!
!
"#$%!&'$%()'*!+,)!-%#%./,*/)-,!0'('!'0,)'(!,#!12(#,#!-'!#3()%!%"? <$&'"#$!
!! ,( )$?*! &).)#$('-,#! 0%*,! :<';$! ,( )$?! 0'('! .,##,#! &')#! -)/%(#,#! $)0,#! -%!
'2-)4.1)'5!6!72)'!).$%)(,!3!1,&0,#$,!0,(!$(4#!/,*2&%#!82%!1,((%#0,.-%&!',#!&9-2*,#!
-'-,#! .,#! .,##,#! 12(#,#:! ;9-2*,! <! =! !"#$%&'()* +* ,-./)'01! ;9-2*,! >! =! ,-./)'*
23&"'.+()* +* 245".)6! %! ;9-2*,! ?! =! 78&'."35! ,-,#! %*%#! 0,-%&! #%(! %.1,.$('-,#! .'!
).$%(.%$!! .'#! 0"7).'#! -,! #(20,! $%$&,.! '&$$0:((7(20,0%$&,.51)*5.%$+!! .'! 0"7).'! -,!
'2$,(! '&$$0:((*'*',)5$,+! %! .'! 0"7).'! -'! 1,&2.)-'-%! $%$&,.! .,! >('#)*!
'&$$0:((---50%$&,..*('#)*51,&5*(+5!
/%#%./,*/%&,#! %#$%! 72)'! 0%.#'.-,! $'&*3&! .,#! '2$,-)-'$'#! 82%! .0,!
0'($)1)0'('&!-,#!.,##,#!12(#,#!%!*')1'('&!%#$%!&'$%()'*!-'!).$%(.%$5!2%!/,14!%#$)/%(!
.%#$'!#)$2'30,!!0,-%!$)('(!-4/)-'#!0,(!%.&')*5!
5%&*('&,#!82%!,!.,##,!,*)%$)/,!.0,!3!%.#).'(!93):3+#+;<)!!%!#)&!72)'(!
/,14!.,#!0'##,#!*"#)1,#!%&!$%$&,.5!2%!#2'!).$%.30,!+,(!'0(%.-%(!'!0(,7('&'(!!0(%+)('!
,!%11%*%.$%!&'$%()'*!-,!0(,+5!521)'.,!6'&'*&,!%&!'&$$0:((---5&'7.%$51,&5*(+5!
6%1,&%.-'&,#! 82%! /,14! '1,&0'.&%! %! )&0*%&%.$%! ,#! %1%&0*,#!! $%.$%!
%.$%.-%(!,#!%((,#!82%!0,-%&!,1,((%(!%!$%.$%!(%#,*/%(!'#!82%#$7%#!82%!%/%.$2'*&%.$%!
'0'(%1%&!',!*,.7,!-%#$%!&'$%()'*5!<,!+).'*!!&"!'*72.#!%1%(181),#!-%!+)1'30,5!
;'.-%! #2'#! -4/)-'#!! #27%#$7%#!! 1(8$)1'#! ,2! 1,&%.$"(),#! 0,(! %.&')*9! 22'!
,0).)0,!#,*(%!,!72)'!3!&2)$,!)&0,($'.$%!0'('!.9#5!
 
 
Josué Labaki 
#(20,!$%$&,.!
/%0'($'&%.$,!-%!".7%.&'()'!;%1:.)1'!
;<"2$!=!?'&02#!-%!=*&'!2,*$%)('!
labaki@feis.unesp.br!
!
" # $ % & ' ( ) * & ! + ! , - $ . & # ! / ! 0 1 ' ( 2 & ! 3 !
$ 4 " # $ 5 % 
 
6 & 7 ( 8 ! 2 + 9 + 4 " ! / ! : % ( , & ! , - $ . & # ! / ! ( # 5 7 , ! / ! " 2 . + ! 7 & 2 $ 5 " % + ! 3
+?&,-=!
,!< =!"!/!$.,? =<! / 
>5<2&%.$'.-,!.,##,!/,1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,! &')#! 1*"##)1,+!! %! ,2$(,#! (%12(#,#!
').-'! 0,-%&! #%(! %.1,.$('-,#! .'! ).$%(.%$! 0'('! -,-.*,'-5! 22'! -,12&%.$'30,! 3! *%&!
/'#$'!!%&*,('!82'#%!1,&0*%$'&%.$%!%&!).7*4#5!62$('!/'.$'7%&!3!82%!'!).#$'*'30,!-,!
0'1,$%! *"#)1,! -%! $%$&,.! 0'('! J).-,-#! )"! 1'((%7'! ,).$%(! '! $)('1,*,! =! 82'*82%(!
1,&02$'-,(!82%!$%.&'!,! ).$%(0(%$'-,(!-%!$%$&,.! ).#$'*'-,!)"!0%(&)$%!1()'(! ).$%(+'1%#!
7("+)1'#! %&! ,).$%(! ''*72&'#! -)#$()*2)37%#! 5).21! (%82%(%&! '! ).#$'*'30,! -%!&9-2*,#!
%#0%1)')#+5!!
!
2?! +'4=? !?&$!?$>>$!7$-!@'>A<,$!
!
<%#$%! ;9-2*,! -,! .,##,! 72)'!! /%(%&,#! '*72.#! .,/,#! $%(&,#! %#0%18+)1,#! -%!
 ,).$%(5! 6! &')#! 2#'-,! 3!!"#$%&!" #$%" &%'%()%" *+$" ,)%-#3001" 2'%" 3" #*%-%" &%)%" *+"
)+4+)5)"%"#$"60$&07+7,+"8#%'8#+)"-%"57,+)4%6+"9)"456%"'#;="?"!"#$%& (!*+"("-.+"/# ++A"
#$"*0,00!"#$"$+7#!"#$%"6%51%"-+",+1,0!"+,61";$"6'58#+"-0"$0#*+"*0*)+"%")%7+'%"-%"
#;=!" *+)%" 7#$"-5-9+," 0#" 7#$" +*&%30" (%K50!" 0#" 0" &)+**507%$+7,0" -+" #$%" ,+6'%" -0"
,+6'%-0!"3"6&%$%-0"-+"%'%(&)1"
B"" ,%$*3$" 0*" %'%(&* +,(#-%./" 'L,)%,%-0)+*" -+" +(+7,0*M+!" 8#+" *00"
&)06+-5$+7,0*" &)09)%$%-0*" &%)%" *+)+$" +1+6#,%-0*" 8#%7-0" #$" +(+7,0" +*&+684560"
%607,+6+1" =*,0" 3!" %0"6'56%)"7#$"*0,00" L2%5)M!"%" )0,57%"8#+" 4+6&%)""%" )%7+'%" '-59%$0*"
8#+" +'%" *+" 6&%$+" L4+6&%NO%7+'%M+" 3" 0" +0+-.( %#-12+"" 60))+*&07-+7,+" %" 6'56%)" 7+*,+"
*0,001"$%)%"8#+"%" )0,57%" 4+6&%NO%7+'%"*+)%"+1+6#,%)%"%"#$"6'58#+"70"*0,00"L2%5)M!"3"
7+6+**")50"4%K+)"0"(#"($"-+*,+"*0,00"60$"%8#+'%")0,57%1"
P+)%" 7%" 459#)%" #$%" %&'56%300" -+" ,57,+)" 4%$0*%!" 0" =/521" 2'+" *+" 60$&0),%"
60$0"*+"*+#"&)09)%$%-0)",5(+**+"+*6)5,0"#$"+(+7,"&%7-'+)"8#+"4%K"0"$+7#"F5'+"'#$"
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 5
-5-9+,+" 456%)" *%',%-0"+" ,5(+**+" '59%-0>"0"+(+7,0" L$%)%)"0"$0#*+"*0*)+"0"$+7#" 45'+M"%"
+*,+"+(+7,"&%7-'+)1"Q#%7-0"0"+(+7,0"%607,+6+" '8#%7-0"%'9#3$"&")%"0"$0#*+" *0*)+"
+**+" -5-9+,+!" 0" +(+7," &%7-'+)" *+" %6507%" +" 0"$+7#" 456%" *%',%-01" <%" (+)-%-+!" 700" 3"
7+6+**")50" 4%K+)" +*,+" ,5&0" -+" %,)5*#5300" 60$" 0" -5-9+," #+-$1" 2'+" 456%" *%',%-0"
%#,0$%,56%$+7,+1"
"
"
5?* +*->!@@A*#.*
"
2+$&)+"8#+",)%*%'&%)$0*"60$" ,57,+)!" 5$&0),%)+$0*",0-0"0"607,+4-0"-+*,+"
$Z-#'01"["6'%**+"56",%$*3$"3"5$&0),%-%!"+"3"-+'%"8#+"607*+9#5$0*",5)%)"0*"-5-9+,*"
60$" 0*" 8#%5*" $07,%)+$0*" 70**%" #;=1" <0**%*" 57,+)4%6+*" 9)"456%*" *+$&)+" *+)00"
+*,)#,#)%-%*" +$" 40)$%" -+" 6'%**+*!" +" #$%" 57*,:765%" -%" 6'%**+" ,!" 8#+" %*%510"
6&%$%$0*" -+" "#&%!" *+$&)+" *+)"" &%**%-%" 60$0" %)9#$+7,0" -0"$3,0-0" 607*,)#,0)" -%"
70**%"#;=1"P+)%",#-0"5**0"70"70**0"&)5$+5)0"+1+$&'0A"
 
from Tkinter import * 
class Janela: 
 def __init__(self, instancia_de_Tk): 
 pass 
raiz=Tk() 
Janela(raiz) 
raiz.mainloop() 
 
1
 To bind: ligar. Também nos referiremos ao processo de binding por “fazer binding”, “ligar”, “relacionar”, 
“atribuir”, etc. 
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 6
["4',5$%"'57&%"4%K"60$"%"57*,:765%"0"8#+"6&%$%$0*"-+"+0+-.(288$1"]"$3,0-0"
9#&-288$"-%"57*,:765%""#&%"4%K"60$"8#+"+**%"#;="458#+"+,+)7%$+7,+"%*+),%"+*&+)%7-0"
&+'0" %607,+65$+7,0" -+" +(+7,0*1" 2+" 0" +(+7,0" 060))5-0" 40)!" &0)" +1+$&'0!" #$" 6'58#+"
7#$%"")+%"40)%"-%"#;=!"7%-%"060))+!"$%*"*+"0"+(+7,0"40)"%'90"60$0"0"&)+**507%$+7,0"
-+" #$" *0,00!" 0" +(+7," &%7-'+)" 60))+*&07-+7,+" *+)"" %6507%-01" ^0$" %" %&'56%300" -0"
$3,0-0"9#&-288$!"%" )%7+'%" 456%"%*+),%"%,3"8#+"060))%"%'9#$"+(+7,0"8#+"%"L-+*,)#%M!"
60$0"#$"6'58#+"70"*0,00"X"-+"4+6&%)"0#"7#$"*0,00"LF+6&%)M"8#+"+(+7,#%'$+7,+"&0**%"
+15*,5)1"
F%'%7-0"+$"*0,00"X!"(+)%"60$0"3"6R$0-0",)%*%'&%)"60$" ,57,+)1"[**5$"8#+"
(06`" 5$&'+$+7,%)" 70**0" +1+$&'0@!" (+)"" 8#+" 0*" *0,7+*" -+" $575$5K%)!" $%15$5K%)" +"
4+6&%)" )"" *00" %#,0$%,56%$+7,+" 60'06%-0*" 7%" *#%" #;=!" %'3$" -%" *%))%" -+" ,8,#'0" +" -0"
*8$*0'0"6%)%6,+)8*,560"-0",57,+)"?"#$" ,"+$"(+)$+'&0"7%"+1,)+$%"+*8#+)-%"-%"*%))%"
-+",8,#'01"P06`"-+(+",+)"0**+)(%-0"0"$+*$0"*8$*0'0"7%")%7+'%"-0"=/521"
['5"*!" 60$0" %&'56%300" -+" ,57,+)!" 0" =/52" ,%$*3$" &0**#5" *+#" &)Z&)50" +(+7,"
'00&"8#+"+7,)%)""+$"6074'5,0"60$"0"-%*"*#%*" 57,+)4%6+*"9)"456%*!"&0)" 5**0"7#76%")0-+"
*+#*"&)09)%$%*"+$" ,57,+)"70"=/521"2$"(+K"-5**0!"&)+45)%"6'56%)"-5)+,%$+7,+"70"8607+"
-0" &)09)%$%" 07-+" (06`" 0" *%'(0#!" 0#" *5$&'+*$+7,+" )+,5)+" %" *+7,+73%" 8#+" 5$&7+" 0"
$%57'00&"S*"*#%*"#;=*1"
"
,!C A*!!*/*0$F !F&$*!*:'!*
"
2?* .,AC!CB',!*A*L!-.*
"
 00"5$&0),%7,+*"8#%7-0"0*"-5-9+,*"*00"0*"607,`57+)+*!"8#+"*00"0*"+'+$+7,0*"
-%" #;=" ?" 7+$" *+$&)+" (5*8(+5*" ?" 07-+" %)+5,%)+$0*" 0*" -5-9+,*1" ]"$%5*" 60$#$" 3" 0"
/"#9+1"
 
2
 Não é necessário implementar os exemplos deste Módulo. Todos eles estão disponíveis para download a 
partir de http://labaki.tk. 
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 7
^0$0" &0-+" &%(+)" #$%" +*,)#,#)%" *+$" 60$&'+1%" -+" 607,`57+)+*" '60$0" #$"
607,`57+)"-+7,)0"-0"0#,)0+!"-+457+.*+"#$%"+*,)#,#)%"&5+)")8#56%"&%)%"700"&+)-+)$0*"0"
607,)0'+" *0*)+" +*,%" +*,)#,#)%1"/59%$0*" 8#+" 7%"#;=" 0" 607,`57+)":+.#" +*,+)%" -5*&0*,0"
-+7,)0"-0" 607,`57+)"&2/#1"[0"-+4575)$0*":+.#!"0"&)5$+5)0"%)9#$+7,0"*+)""&2/#!"0"8#+"
57-56%"8#+"&2/#"3"L&%5M"'0#"L$+*,)+M+"-+":+.#A"607,`57+)e+,%' 8-.'&-+"&2/#=111111+1"
J5-9+,*"*+9#+$"%"$+*$%"*57,%1+A"0"&)5$+5)0"%)9#$+7,0"70"57*,%7,+"-%"*#%"
-+4575300"-+(+"57-56%)"8#+$"3"*+#"607,`57+).&%5"?"0"607,`57+)"-+7,)0"-0"8#%'"0"-5-9+,"
-+(+)""+*,%)"*5,#%-01"
]" +'+$+7,0" $"15$0" -%" &5+)%)8#5%" 3" %" &)Z&)5%" )%7+'%" ,0&.'+(+'!" %8#+'%" 8#+"
(+$"60$"0*"*0,7+*"-+"4+6&%)!"*%))%"-+",8,#'0!"+,61"P+)%"#$"+*8#+$%"&5+)")8#560A"
"
[&Z*"%"-+4575300"-+"#$"607,`57+)"0#"-5-9+,!"&)+65*%$0*"#*%)"#$"9+)+765%-0)"
-+"9+0$+,)5%"&%)%"57-56%)"+$"8#+"&0*5300"+'+"%&%)+6+)""-+7,)0"-0"*+#"$+*,)+1" ,57,+)"
04+)+6+" ,)`*A" >"&1!" $# 6" +" $2# +1" <+*,+" ,#,0)5%'" #*%)+$0*" 0" $# 6!" +" *+$" 70" 457%'"
4%'%)+$0*" *0*)+" >"&1!" $%*" (06`" &0-+" -+*60*)5)" 0" 9+)+765%-0)" $2# +" 607*#',%7-0" 0*"
'5()0*" )+60$+7-%-0*"%0" 457%'"-+*,+"gZ-#'01"2+"7+7&#$"9+)+765%-0)"-+"9+0$+,)5%" 40)"
%&'56%-0"%0"-5-9+,!"+'+"+15*,5)"!"$%*"700"*+)""(5*8(+'"%0"#*#")509"<+*,+"6%*0"0"-5-9+,"3"
6&%$%-0" -+" 0&".$#2" +" *+)(+!" &0)" +1+$&'0!" &%)%" 6)5%)" #$%" #;=" 57(5*8(+'" 8#+"$+*$0"
%**5$"&+)$5,5**+"%"%,)5*#5300"-+"#$"+(+7,0"%"#$"&)06+-5$+7,01"
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 8
5?* %*-$F C,FAC*1.,2%*A*$*D,&1A *0)&3)*
"
^)5%)+$0*" #$" +1+$&'0" 8#+" +7(0'(+)"" 0*" ,5&0*"$%5*" 60$#7*" -+" 607,`57+)" +"
-5-9+,A"("#9+"+":$..8-1"<0"+1+$&'0!"0**+)(+"60$0"0"$+*,)+"-0"4)%$+"'%")%7+'%",0&.
'+(+'+" +" -0" *0,00" '0" 4)%$+" 8#+" 6&%$%$0*" -+" /")+" *00" &%**%-0*" 60$0" &)5$+5)0"
%)9#$+7,01" [" *57,%1+"self.fr1" 57-56%" 8#+" 0" 4)%$+!" 60$"8#%'8#+)"-5-9+,!" 3" ,)%,%-0"
60$0"#$"%,)5*#,0"-%"57*,:765%"-%"6'%**+" ,1"]**+)(+",%$*3$"%"#,5'5K%300"-0"$# 6"&%)%"
,0)7%)"0*"-5-9+,*"+"607,`57+)+*"(5*8(+5*1"
[" *57,%1+"&%)%" 6)5%)"#$"-5-9+,"8#%'8#+)"3"*89++18+,&1>+.-9+*."+=(8$E.+*(
1+( 8-/&>$"#EG8/1" [0" '0790" -+*,+" gZ-#'0" 607&+6+)+$0*" %*" &)5765&%5*" 0&37+*" -+"
607459#)%300"-5*&078(+5*"&%)%"%'9#7*"-5-9+,*1"$0)"+78#%7,0"(%$0*"607459#)%)"*0$+7,+"
%"60)"+"0",+1,0"-0"*0,001"
 
from Tkinter import * 
class Janela: 
 def __init__(self,toplevel): 
 self.fr1 = Frame(toplevel) 
 self.fr1.pack() 
 self.botao = Button(self.fr1, text='Oi!', background='green') 
 self.botao.pack() 
 
raiz=Tk() 
Janela(raiz) 
raiz.mainloop() 
"
$A@'> !&$E*
" "
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 9
['3$"-+*,%")%7+'%!"-+(+",+)"%&%)+65-0",%$*3$"#$%")%7+'%"&)+,%"-0"*6)5&,"-+"
$%,&071" ^%*0" (06`" 700" 8#+5)%" 8#+" +'%" *+)%" (5*8(+'!" *%*,%" *%'(%)" *+#" %)8#5(0" 60$"
+1,+7*00"$I,1"
["0&300"T*%6,9)0#7-U"$#-%"%"60)"-+"4#7-0"-0"*0,001"2$"(+K"-+"T*%6,9)0#7-U!"
&0-+)8%$0*",+)"%*)+(5%-0"0"70$+"60$0"T*9U1""
]*" -5-9+,*" 9#%)-%$" *#%*" 0&37+*" -+" 607459#)%300" +$" 40)$%" -+" -56507")50*1"
$0)"5**0!",%$*3$"&0-+)8%$0*"607459#)%)"%*"0&37+*"-0"*0,00"&0)"$+50"-+A"
self.botao['bg']='green' 
;$"4%,0"70,"(+'"3"8#+"%")%7+'%"-5$57#5#"-+",%$%7&0"+$")+'%300"%0"+1+$&'0"
%7,+)50)1"<0"&)5$+5)0"+1+$&'0!"0",%$%7&0"-%")%7+'%"+)%"0",%$%7&0"&%-)00"-+")%7+'%*"
*+$"-5-9+,*1"["&%),5)"-0"$0$+7,0"+$"8#+"#$"4)%$+"3"%-56507%-0!"%" )%7+'%"&%**%"%"
,+)" 0" ,%$%7&0" -0" 4)%$+1" $0)" 0#,)0" '%-0!" 0*" 4)%$+*" *00" +'"*,560*A" *+#" ,%$%7&0" 3"
+1%,%$+7,+"0",%$%7&0"-0*"-5-9+,*"8#+"+'+*"607,3$1""
F%3%"#$",+*,+1";*+"0"$+*$0"+1+$&'0!"$%*")+,5)+"0"*0,00"'(06`"700"&)+65*%"
%&%9%)"%*"'57&%*"8#+"0"-+457+$!"*%*,%"700"%&'56%)"0"$3,0-0"&%6,+1"[")%7+'%"%90)%"*+"
)+-#K"%0",%$%7&0"$875$0!"700"3V"
$0)" 0#,)0" '%-0!" %" %-5300" -+" $%5*" #$" *0,00" 4%K" 0" 4)%$+" *+" +*,56%)" &%)%"
60$&0),%.'0*!" 60$0"70" +1+$&'0" *+9#57,+1"<+*,+"+1+$&'0!" %&)0(+5,+"&%)%"0**+)(%)" %"
607459#)%300"-+"$%5*"8#%,)0"0&37+*"-0"-5-9+,"e#,,07A"
• +%"$+&"?"*+)(+"&%)%"607459#)%)"8#%'"3"%"%',#)%"-0"*0,00"+$"74$+)0"-+"
'57&%*"-+",+1,0W"
• !"#&+"?"+*&+65456%"%"'%)9#)%"-0"*0,00"+$"8#%7,5-%-+"-+"'+,)%*W"
• 1)(&" ?" 60$" +*,%" (06`" &0-+" 607459#)%)" %" 407,+" -0" ,+1,0" -0" *0,00"
%,)%(3*"-+"#$%",#&'%A"'L,5&0"-%"407,+M!"L,%$%7&0M!"L7+9)5,0M!"L5,"'560M!"
1111+W"
• "1$"?"0"$+*$0"8#+"/8"+>"8$-11"2+)(+"&%)%"607459#)%)"%"60)"-0",+1,01"
 
 
 
 
 
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 10
from Tkinter import * 
class Janela: 
 def __init__(self,toplevel): 
 self.fr1 = Frame(toplevel) 
 self.fr1.pack() 
 
 self.botao1 = Button(self.fr1,text='Oi!') 
 self.botao1['background']='green' 
 self.botao1['font']=('Verdana','12','italic','bold') 
 self.botao1['height']=3 
 self.botao1.pack() 
 
 self.botao2 = Button(self.fr1,bg='red', font=('Times','16')) 
 self.botao2['text']='Tchau!' 
 self.botao2['fg']='yellow' 
 self.botao2['width']=12 
 self.botao2.pack() 
 
raiz=Tk() 
Janela(raiz) 
raiz.mainloop() 
"
$A@'> !&$E*
"
P+)%"60$0"0"4)%$+"%)#*,%"*+#",%$%7&0"%#,0$%,56%$+7,+"&%)%"60$&0),%)"0*"
-05*"*0,7+*1"]**+)(+"%"407,+"-0"*0,00"(+)-+!"P+)-%7%",%$%7&0">@"+$"5,"'560"+"7+9)5,0"
'*0'-+!"+"%" 407,+"-0"*0,00"(+)$+'&0!" 5$+*"<+-"60$%7",%$%7&0">C1"]"*0,00"(+)-+"
&0**#5"%90)%",)`*"'57&%*"-+"%',#)%"+78#%7,0"0"(+)$+'&0",`$">@"'+,)%*"-+"'%)9#)%!"%'3$"
-0" *+#" ,+1,0" *+)" %$%)+'0!" 60$0" 405" 607459#)%-0" %,)%(3*" -%" 0&300" L49M1" [7,+*" -+"
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 11
&)0**+9#5)$0*!" 4%3%" *+#*" &)Z&)50*" ,+*,+*" 60$" %*" *+5*" 0&37+*" 8#+" %&)+7-+$0*" %,3"
%90)%1" ^)5+" (")50*" *0,7+*" 60$" (")5%*" 60)+*!" 407,+*" +" ,%$%7&0*1" 2+)"" *0$" 8#+" (06`"
,+7&%",)%8#+)0"7+*,%*"607459#)%37+*!"&0)8#+"+'%*"*00"$#5,0"#*%-%*1"
"
6?* ,$@,-,$F!F&$*D,&1A @*F!*:'!*
"
]"$%5*"5$&0),%7,+"%"0**+)(%)$0*"70"+1+$&'0"%7,+)50)"3"%"-5*&0*5300"8#+"0*"
*0,7+*" %**#$5)%$" 70" 4)%$+1" Q#+$" -+,+)$570#" 8#+" 0" J8.#80" *+" &0*56507%**+" *0*" 0"
J8.#8)"405"0"9+)+765%-0)"-+"9+0$+,)5%"8#+"#*%$0*!"0"$#61"
=$%957+" 8#+" #$" 4)%$+" *+)%" #$%" 6%(5-%-+" 07-+" +76%51%$0*" 0*" -5-9+,*1" ]"
$3,0-0" &%6," &0**#5" #$" %)9#$+7,0" *&1+" 6%&%K" -+" %**#$5)" 8#%,)0" (%'0)+*!" 52F "
'+*8#+)-%+!" 6=#B " '-5)+5,%+!" ]$" '+$" 65$%+" +" e] ]g" '+$*%510+!" 8#+" -+,+)$57%$"
+$"8#+"'#9%)"-%"6%(5-%-+"0"-5-9+,"-+(+"*+"&0*56507%)1""
[**5$" 8#+" #$"-5-9+," 3" &0*56507%-0!" 0" +*&%30" )+*,%7,+" &%**%" %" *+)" %" 70(%"
6%(5-%-+" 07-+" 0" &)Z15$0" -5-9+," *+)"" &0*56507%-0!" 8#%7-0" %&'56%)$0*" *0*)+" +'+" 0"
$3,0-0" &%6,1" <00" 3" ,00" *5$&'+*" 0**+)(%)" 5**0" &0)8#+" 0" 4)%$+" *+" +760'&+" *0*)+" 0"
&)5$+5)0"-5-9+,!"+7,00"0"L+*&%30")+*,%7,+M"3"*5$&'+*$+7,+" 5$%957")501"Q#+$"*%*+"%"
459#)%"%"*+9#5)"700"+*6'%)+3%"#$"&0#60"%"8#+*,00V"
"
]" (%'0)" &%-)00" -0" %)9#$+7,0" *5-+" 3" ]$1" $0)" 5**0!" 8#%7-0" %&'56%$0*" 0"
$3,0-0"&%6,"*0*)+"0*"*0,7+*"-0"+1+$&'0"%7,+)50)!"0"*0,00"L]59M"*+"&0*56507%"70",0&0"
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 12
-%" 6%(5-%-+!" +" 0" *0,00" L 6&%#9M" *+" &0*56507%" 70" ,0&0" -%" 6%(5-%-+" )+*,%7,+!" 5*,0" 3!"
%*%510" -0" &)5$+5)0" *0,001" <#76%" %&'58#+" -54+)+7,+*" &0*56507%$+7,0*" -+" -5-9+,*" 70"
$+*$0"4)%$+9"]"+4+5,0"&0-+"*+)"-+*%*,)0*0"&)5765&%'$+7,+"8#%7-0"0"#*#")50")+*0'(+)"
)+-5$+7*507%)"%")%7+'%"'6'56%7-0"70"*0,00"-+"$%15$5K%)!"&0)"+1+$&'0+1"2$"(+K"-5**0!"
6)5+"(")50*"4)%$+*!"60$0"70"+1+$&'0"%"*+9#5)1"/+7,)0"-+"6%-%"#$"-+'+*!"*Z"#$"(%'0)"3"
%&'56%-0" S" 0&300" *5-+!" +" $+*$0" %**5$" 607*+9#5$0*" 60'06%)" 0*" *0,7+*" +$" &0*537+*"
(%)5%-%*"7%"#;=1"
 
from Tkinter import * 
class Packing: 
 def __init__(self,instancia_Tk): 
 
 self.container1=Frame(instancia_Tk) 
 self.container2=Frame(instancia_Tk) 
 self.container3=Frame(instancia_Tk) 
 self.container1.pack() 
 self.container2.pack() 
 self.container3.pack() 
 
 Button(self.container1,text='B1').pack() 
 Button(self.container2,text='B2').pack(side=LEFT) 
 Button(self.container2,text='B3').pack(side=LEFT) 
 self.b4=Button(self.container3,text='B4') 
 self.b5=Button(self.container3,text='B5') 
 self.b6=Button(self.container3,text='B6') 
 self.b6.pack(side=RIGHT) 
 self.b4.pack(side=RIGHT) 
 self.b5.pack(side=RIGHT) 
 
raiz=Tk() 
Packing(raiz) 
raiz.mainloop() 
*
*
*
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 13
$A@'> !&$E*
"
^)5%$0*" ,)`*" 4)%$+*!" 60$0" (06`" &R-+"(+)1"[&'56%$0*"&%6,'*5-+X ]$+" *0*)+"
0*" ,)`*!" +7,00" +'+*" +*,00" +$&5'&%-0*" #$" *0*)+" 0*" 0#,)0*1" ^0$0" 0" (%'0)" &%-)00" -0"
%)9#$+7,0" *&1+" 3" ]$!" 700" &)+65*"(%$0*" &%**%)" 5**0" +1&'565,%$+7,+1" <0(%$+7,+"
#*%7-0" &%6,'*5-+X ]$+!" 6)5%$0*" #$" *0,00" &0*56507%-0" 70" &)5$+5)0" 4)%$+!" 8#+" *+"
-5*&7+" 70" ,0&0" -%" *#%" 6%(5-%-+1" /05*" 0#,)0*" *0,7+*" *00" 6)5%-0*" +" &0*56507%-0*" 70"
*+9#7-0"4)%$+!"$%*"-+*,%"(+K"60$"%"0&300"&%6,'*5-+X52F +1"Y"&0)"5**0"8#+"0"*0,00"
Le@M" *+" &0*56507%" S" +*8#+)-%" 70" 4)%$+" +" 0" *0,00" LeEM" *+" &0*56507%" S" +*8#+)-%" -%"
6%(5-%-+")+*,%7,+1"
[90)%" &)+*,+" %,+7300" 70" 8#+" 45K+$0*" 70" ,+)6+5)0" 4)%$+1" )`*" *0,7+*" 40)%$"
6)5%-0*"7#$%"0)-+$"'*?!"*A!"*C+"+"0"$3,0-0"&%6,'*5-+X6=#B +"405"%&'56%-0"*0*)+"+'+*"
+$" 0)-+$" -54+)+7,+1" P+)%" 8#+" +'+*" 40)%$" *+" &0*56507%7-0" S" -5)+5,%" 7%" 6%(5-%-+" -0"
4)%$+" 8-.#&-+"1"7%"0)-+$"+$"8#+"0"$3,0-0"405"%&'56%-0"'*C!"*?!"*A+1"
21&+)5$+7,+9" ^)5+" (")50*" *0,7+*" +" 4)%$+*!" +" 60'08#+.0*" +$" -5*&0*537+*"
-54+)+7,+*" 7%" #;=W" %&'58#+" 0" $3,0-0" &%6," +$" 0)-+$" -54+)+7,+" -%" 8#+" 0*" -5-9+,*"
40)%$"6)5%-0*1"
!"" 23# $3%&'(# )*%+'(# ,-# './-%'01*# 4$-# $* '# 6*,-# )'%-%# 8*# -5-+6.*#
'8/-%&*%#,-#)*%+'#'#,-&5':.*# *+*#'#)&;$%'#'#(-;$&%6#7$# *8(&;*#)'%-%#&((*#
'./-%'8,*#'6-8'(#,*&(# '%' /-%-(>#7#$* '8#
!
!
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 14
,!< >*!!!*/*9,@&,@1*
!
O"! $%&'(! )*+! +$+,-! &/,01+2(! (0'! /(! /37+(! +1+7*-/0/(! +&! 2+(8'(-/! /! *&!
+$+,-'9! :(-2*-*2/,0'! ,'((/! %,-+2;/7+! <2";%7/! +&! 71/((+(!! 8'0+&'(! +(72+$+2! +$+,-!
&/,01+2(!,/!;'2&/!0+!&>-'0'(!?!;*,37+(!0+;%,%0/(!0+,-2'!0/!71/((+9!!
@! 41-%&'! 8/(('! >! /-2%**%2! '! +$+,-'! /'! +$+,-! &/,01+29! $/2/! %(('! *(/&'(! '!
&>-'0'!@&8,!/-2/$>(!0/!(%,-/1+!,&,;-/6@&8,-#-$-8/*#C#-$-8/#D'8,.-%/9!
!
2?* 57>@ $G*&$*4$'G>*
!
@!L+$+,-'M!7'&'!*&!71%)*+!0'!&'*(+!'*!'!82+((%',/&+,-'!0/!-+71/!:< :6!>!
8/((/0'!7'&'!/2<*&+,-'!0'!&>-'0'!@&8,!7'&'!*&/!(-2%,<9!$'2!+1+&81'!!(+!'!+$+,-'!
>! *&! 71%)*+! 7'&! '! *'-0'! +()*+20'! 0'!&'*(+!! /! (-2%,<! >! "<Button-1>"!! +! /! (-2%,<!
7'22+(8',0+,-+!/'!82+((%',/&+,-'!0/!-+71/!:< :6!>!"<Return>"9!
/%</&'(! )*+! *&! &>-'0'! 7&/&/0'! +$,'+ *%! 0+$/! (+2! +1+7*-/0'! )*/,0'!
/1<*>&! 71%7/2! 7'&! '! *'-0'! +()*+20'! 0'!&'*(+! ('*2+! '! *'-0'!@*/'*$-%,-9! J! (%,-/1+!
8/2/!;/K+2!+((/!7',+10'!+$+,-'(+$+,-!&/,01+2!(+2%/M!
self.botaoverde.bind("<Button-1>", self.muda_cor) 
Y!'!)*+!;/K+&'(!,'!+1+&81'!/*/%1'9!J82'$+%-/&'(!,'(('!8'0+2!0+!&/,%8*1/2!
7/2/7-+28(-%7/(!0+!-%0<+-(!8'2!&+%'!0+!0%7%',"2%'(!8/2/!/1-+2/2!/!7'2!0+!*&!*'-0'!/((%&!
)*+!+1+!>!71%7/0'9!
J82'$+%-/&'(!/!0+%1/!8/2/!&'(-2/2!&/%(!*&!-%8'!0+!-%0<+-!!9'@-.!!7'&!'!)*/1!
8'0+&'(! &'(-2/2! 8+)*+,'(! -+1-'(! ,/! -+1/9! @! 9'@-.! 8'((*%! -'0/(! /(! '837+(! 0+!
7',;%<*2/30'!)*+!$'7Q!)"!7',&+7+!0'!S*--',!'/-5/!!,&,/D!!+-79+9!
 
 
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 15
from Tkinter import * 
class Janela: 
 def __init__(self,toplevel): 
 
 self.frame=Frame(toplevel) 
 self.frame.pack() 
 
 self.texto=Label(self.frame, text='Clique para ficar amarelo') 
 self.texto['width']=26 
 self.texto['height']=3 
 self.texto.pack() 
 
 self.botaoverde=Button(self.frame,text='Clique') 
 self.botaoverde['background']='green' 
 self.botaoverde.bind("<Button-1>",self.muda_cor) 
 self.botaoverde.pack() 
 
 def muda_cor(self, event): 
 # Muda a cor do botao! 
 if self.botaoverde['bg']=='green': 
 self.botaoverde['bg']='yellow' 
 self.texto['text']='Clique para ficar verde' 
 else: 
 self.botaoverde['bg']='green' 
 self.texto['text']='Clique para ficar amarelo' 
 
raiz=Tk() 
Janela(raiz) 
raiz.mainloop() 
!
$>G'> !&$E*
!
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 16
;&! 71%)*+! ,'! *'-0'! $+20+! 7&/&/! '!&>-'0'!+$,'+ *%! +! /! 7'2! 0+! ;*,0'! 0'!
*'-0'!&*0/!8/2/!/&/2+1'9!@*-2'!71%)*+!-2/K!0+!$'1-/!/!7'2!'2%<%,/19!
 '0'!+$+,-'!)*+!'7'22+!+&! ,%,-+2!<+2/!*&!'*)+-'#-$-8/*9!@!'*)+-'#-$-8/*!>!
*&!-%8'!+(8+7%/1!0+!'*)+-'!7',-+,0'!%,;'2&/37+(!%&8'2-/,-+(!('*2+!'!+$+,-'!'7'22%0'9!
 /%(!%,;'2&/37+(!(0'!;*,0/&+,-/%(!8/2/!'(!+$+,-!&/,01+2(!!8'2!%(('!+(-+(!+1%<+&!)*+!
'(! '*)+-'(! -$-8/*! (+)/&! 8/((/0'(! 7'&'! /2<*&+,-'!! 7'&'! $'7Q! '*(+2$/! +&!
muda_cor(self, event)9!
X'&'!(Y!/(('7%/&'(!'!+$+,-'!:I$//*8:);!/'!&>-'0'!!*&!71%)*+!7'&!'!*'-0'!
0%2+%-'!0'!&'*(+!,0'!8'((*%!+;+%-'!('*2+!/!#;=9!2+!)*%(>((+&'(!'!7',-2"2%'!!-+28/&'(!
)*+!*(/2!/!(-2%,<!:I$//*8:1;!!7'22+(8',0+,-+!/'!*'-0'!0%2+%-'!0'!&'*(+9!@!82%&+%2'!/2<*&+,-'!0'!&>-'0'!*%,0!-/&*>&!8'0+!(+2!*&/!-*81/!7',-+,0'!
'(! +$+,-'(! ,/! '20+&! +&! )*+! +1+(! 0+$+&! '7'22+2! 8/2/! )*+! '! +$+,-! &/,01+2! (+)/!
0+(+,7/0+/0'9!2+!'!7Y0%<'!;'((+!
self.botaoverde.bind(("<Button-1>","<Button-3>"), self.muda_cor) 
!('&+,-+! *&! 71%)*+! 7'&! '! *'-0'! +()*+20'! (+<*%0'! 0+! *&! 71%)*+! ,'! *'-0'!
0%2+%-'! /7%',/2%/! '!&>-'0'9! :(-/! ->7,%7/! >! %,-+2+((/,-+! (+! $'7Q! )*%(+2! /(('7%/2! *&/!
7'&*%,/30'!0+!-+71/(!/!*&!+$+,-'9!
@(! -%0<+-(! -/&*>&! (0'! 7/8/K+(! 0+! 2+(8',0+2! /! +$+,-'(! 0+! &'*(+! 7'&'!
(%&81+(&+,-+! 8/((/2! '! 8',-+%2'! 0'! &'*(+! ('*2+! '! -%0<+-9! F/3/! (+*(! +18+2%&+,-'(!
8/2/!;%7/2!72/)*+!,%(('9!J!(-2%,<!"<ButtonRelease-X>"!7'22+(8',0+!/!('1-/2!'!*'-0'!Z!
0'!&'*(+!'Z!8'0+!(+2!%<*/1!/!>!!@!'*!E!!&/(!,+&!-'0'(!'(!&'*(+(!8'((*+&!'!*'-0'!
0'!&+%'+9! J! (-2%,<! "<Motion>"! 2+82+(+,-/! '! +$+,-'! 0+!&'$+2! '! 8',-+%2'! 0'!&'*(+!
('*2+!'!-%0<+-!!+,)*/,-'!"<Leave>" 2+82+(+,-/!/!2+-%2/0/!0'!8',-+%2'!0'!-%0<+-9!
!
!
!
!
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 17
5?* F$-$*>*>7>@ $G*&>* >->!&$*
!
@! )* *! >! '! &+7/,%(&'! )*+! %,0%7/! )*/1! -%0<+-! +(-"! 2+(8',0+,0'! +&!
0+-+2&%,/0'!&'&+,-'! 8+1'(! +$+,-'(! 0+! -+71/0'9! /Q! *&/! '1&/0/! ,'! <+2+,7%/0'2! 0+!
/2)*%$'(!0'!(+*!(%(-+&/!'8+2/7%',/1!'J%,0'-(!:181'2+2!!8'2!+1+&81'+9!2+!$'7Q!71%7/2!
,'!,'&+!0+!*&!/2)*%$'!!$+2"!)*+!+1+!;%7/!+&!0+(-/)*+!?!7'&!*&!2+-:,<*1'!8',-%1&/0'!
/'! (+*! 2+0'2!! -/1$+K! +&! /K*19! :(-+! 0+(-/)*+! >! '! &+%'! +(7'1&%0'! 8+1'! (+*! (%(-+&/!
'8+2/7%',/1! 8/2/! %,0%7/2! )*+! /)*+1+! /2)*%$'! +(-"! +&! ;'7'9! </! '7/(%0'! 0+! '7'22+2! '!
+$+,-'! L82+((%',/2! /:5: :M!! ('&+,-+! '! /2)*%$'! +&! ;'7'! (+2"! +171*80'9! P'7Q! 8'0+!
8/((/2! '! ;'7'! 8/2/! '! /2)*%$'! (+<*%,-+! 82+((%',/,0'! JS!! '*! $'1-/2! '! ;'7'! 8/2/! '!
/,-+2%'2! 82+((%',/,0'! 2B=F [ JS!! '*! /%,0/! 71%7/,0'! ('*2+! '! /2)*%$'9! '0'(! +(-+(!
7'&8'2-/&+,-'(!+1%*%0'(!8+1'(!/2)*%$'(!0'!(+*!(%(-+&/!'8+2/7%',/1!(0'!/82+(+,-/0'(!
8+1'(!-%0<+-(!0+! ,%,-+29!
;&! &>-'0'! %&8'2-/,-+! )*/,0'! (+! ;/1/! +&! ;'7'! +&! ,%,-+2! >!
,&,;)6)* $(+)*% --/!!*(/0'!8/2/!8/((/2!'!;'7'!8/2/!'!-%0<+-!,&,;)9!
P+)/!,/!-/*+1/!/!(-2%,<!7'22+(8',0+,-+!/!/1<*,(!+$+,-'(!7'&*,(!0+!-+71/0'9!
!
57>@ $* 7 <,@1*
:< :6! "<Return>" 
/:5: :! "<Delete>" 
S/7,(8/7+! "<BackSpace>" 
:2X! "<Escape>" 
2+-/!S!+()*+20/! "<Left>" 
2+-/!S!0%2+%-/! "<Right>" 
2+-/!8/2/!7%&/! "<Up>" 
2+-/!8/2/!*/%1'! "<Down>" 
@!-%0<+-!</,&/!;'7'! "<FocusIn>" 
@!;'7'!(/%!0'!-%0<+-! "<FocusOut>" 
!
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 18
;(+!/!(-2%,<!"<KeyPress-ALFA>"!8/2/!2+82+(+,-/2!'!82+((%',/&+,-'!0+!*&/!
-+71/! J5FJ!! +! "<KeyRelease-ALFA>"! 8/2/! 2+82+(+,-/2! '! *(*"2%'! ('1-/,0'! +(-/! -+71/9!
P/1+! (%&81%;%7/2! "<KeyPress-ALFA>"! ! 7'&'! "ALFA"9! F/1/,0'! ,%(('!! '! %,-+282+-/0'2!
-/&*>&!+,-+,0+!"<Button-1>"!7'&'!"<1>"9!
B"!*,(!&'0%;%7/0'2+(!0+!+$+,-'!%&8'2-/,-+(9!$'0+&'(!*(/2!'(!&'0%;%7/0'2+(!
<*$@.-! +! N%&6.-! 8/2/! 2+82+(+,-/2! 0*/(! '*! -2Q(! 2+8+-%37+(! 0+! *&! +$+,-'! +&! 2"8%0/!
(*7+((0'9! =(-'! >!! 8'0+&'(! *(/2!"<Double-Button-1>"! 8/2/! 2+82+(+,-/2!0*81'! 71%)*+!
7'&!'!*'-0'!+()*+20'!0'!&'*(+!'*!"<Triple-KeyPress-P>"! 8/2/! 2+82+(+,-/2! -2%81'!
82+((%',/&+,-'! 7',(+7*-%$'! 0/! -+71/! $9! @! &'0%;%7/0'2! &8P! (+2$+! 8/2/! %,0%7/2! '!
82+((%',/&+,-'! 0+! )*/1)*+2! -+71/! '*! *'-0'! 0'! &'*(+W! /(! (-2%,<(! 7'22+(8',0+,-+(!
"<Any-KeyPress>" (0'!+!"<Any-Button>"!!2+(8+7-%$/&+,-+9!!
P+)/&'(! *&! +1+&81'! 7'&! -*0'! '! )*+! /7/*/&'(! 0+! ;/1/29! J<'2/!
/82+,0+2+&'(! /%,0/! -2Q(! ,'$/(! '837+(! 0+! 7',;%<*2/30'! 0'(! *'-7+(!! %-.&-)!! 6',5! +!
6',P9!=-.&-)! (+2$+! 8/2/!&*0/2! '! 2+1+$'! 0'! *'-0'9!@(! $/1'2+(.8/020'! /! )*+! +(-/&'(!
/7'(-*&/0'(! (0'! 2;<\:<! )*/,0'! '! *'-0'! >! 82+((%',/0'! +! 6J=2:/!! 7/('! 7',-2"2%'9!
:18+2%&+,-+!'(!'*-2'(!$/1'2+(!#6@@P:!!6=/#:!+!F5J 9!O"!6',5!+!6',P!(0'!'(!+(8/3'(!
+1-2/(!)*+!0/&'(!+,-2+!/(!*'20/(!0+!-%0<+-(!7'&'!I$//*8!+!9'@-.!+!'!-+1-'!7',-%0'!
,+1+(!!$+)/M!
!
P/&'(!/'!7Y0%<'999!J!82%&+%2/!1%,&/!>!/0%7%',/0/!8/2/!)*+!/!<+,-+!8'((/!*(/2!
7/2/7-+2+(! +(8+7%/%(!! 7'&'! /7+,-'(!! /'! 1',<'! 0'! 82'<2/&/9! <0'! 0+%1+! 8/((/2!
0+(8+27+*%0'! '! 6' R:$86' R! )*+! *(/&'(! 8/2/! /<%1%K/2! /! 0+-+2&%,/30'! 0/(!
7/2/7-+28(-%7/(!0'(!*'-7+(9!
!
!
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 19
# -*- coding: cp1252 -*- 
from Tkinter import * 
class Janela: 
 def __init__(self,toplevel): 
 self.frame=Frame(toplevel) 
 self.frame.pack() 
 self.frame2=Frame(toplevel) 
 self.frame2.pack() 
 
 self.titulo=Label(self.frame,text='VIDENTE 2005', 
 font=('Verdana','13','bold')) 
 self.titulo.pack() 
 
 self.msg=Label(self.frame,width=40,height=6, 
 text = 'Adivinho o evento ocorrido!') 
 self.msg.focus_force() 
 self.msg.pack() 
 # Definindo o botão 1 
 self.b01=Button(self.frame2,text='Botão 1') 
 self.b01['padx'],self.b01['pady'] = 10, 5 
 self.b01['bg']='deepskyblue' 
 self.b01.bind("<Return>",self.keypress01) 
 self.b01.bind("<Any-Button>",self.button01) 
 self.b01.bind("<FocusIn>",self.fin01) 
 self.b01.bind("<FocusOut>",self.fout01) 
 self.b01['relief']=RIDGE 
 self.b01.pack(side=LEFT) 
 # Definindo o botão 2 
 self.b02=Button(self.frame2,text='Botão 2') 
 self.b02['padx'],self.b02['pady'] = 10, 5 
 self.b02['bg']='deepskyblue' 
 self.b02.bind("<Return>",self.keypress02) 
 self.b02.bind("<Any-Button>",self.button02) 
 self.b02.bind("<FocusIn>",self.fin02) 
 self.b02.bind("<FocusOut>",self.fout02) 
 self.b02['relief']=RIDGE 
 self.b02.pack(side=LEFT) 
 
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 20
 def keypress01(self,event): self.msg['text']='ENTER sobre o Botão 1' 
 def keypress02(self,event): self.msg['text']='ENTER sobre o Botão 2' 
 def button01(self,event): self.msg['text']='Clique sobre o Botão 1' 
 def button02(self,event): self.msg['text']='Clique sobre o Botão 2' 
 def fin01(self,event): self.b01['relief']=FLAT 
 def fout01(self,event): self.b01['relief']=RIDGE 
 def fin02(self,event): self.b02['relief']=FLAT 
 def fout02(self,event): self.b02['relief']=RIDGE 
 
raiz=Tk() 
Janela(raiz) 
raiz.mainloop() 
 
$>G'> !&$E*
!
J'! 0+;%,%2&'(! '! 1/*+1! +(;!! /81%7/&'(! ('*2+! +1+! '! )* $(+)*% -9! $'2! %(('!!
)*/,0'!'!82'<2/&/!>!%,%7%/0'!!'!;'7'!>!%&+0%/-/&+,-+!8/((/0'!8/2/!+(-+!-%0<+-9!P'7Q!
8'0+!$+2%;%7/2!)*+!82+((%',/2!:< :6!,+(-+! %,(-/,-+!,0'!7&/&/!+$+,-!&/,01+2!/1<*&9!
J'!82+((%',/2&'(! JS!!'!;'7'!>!+,-0'!8/((/0'!8/2/!'!-%0<+-!0+;%,%0'!1'<'!/8Y(!+(;!!
)*+!>!'!S'-0'!>9!P'7Q!8'0+2%/!$+2!%(-'!8+1'!2+-:,<*1'!)*+!7%27*,0/2%/!'!-+1-'!0'!*'-0'9!
J<'2/!(%&!!7'&'!2+1/7%',/&'(!'!82+((%',/&+,-'!0+!:< :6!('*2+!'!S'-0'!>!/'!+$+,-!
&/,01+2!R-P6%-((>)!!+(-+!&>-'0'!(+2"!7&/&/0'!!/1-+2/,0'!'!1/*+1!+(;9!
<0'! 0+%1+! 0+! ,'-/2! )*+! 1%</&'(! '(! +$+,-'(! ](* $("8^! +! ](* $(V$/^! /'!
S'-0'! >9! Y! 8'2! %(('! )*+! '! 2+1+$'! 0'! *'-0'!&*0/! ,'! %,(-/,-+! )*+! '! ;'7'! >! 0/0'! '*!
2+-%2/0'!0+1+9!
! " # $ %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+(-+! +$+,-'!
7'22%)*+%2'!/!*&!+$+,-!&/,01+2!!(+&!/!,+7+((%0/0+!0+!/81%7/2!'!&>-'0'!*%,0999!/+!;/-'!!
&"M!>!'!7'&&/,0!*%,0%,<9!:(-+!2+7*2('!8+2&%-+!/(('7%/2!'!71%)*+!0'!&'*(+!('*2+!*&!
-%0<+-!0*2/,-+!/!82Y82%/!0+;%,%30'!0'!-%0<+-!!7'&'!/!(+<*%2M!
Widget(master, ...., command = self.event_handler) 
<'! ;%&! 0/(! 7',-/(!! +(-+! *%,0%,<! (+! 7'&8'2-/! 7'&'! *&/! '830'! 0+!
7',;%<*2/30'!0'!-%0<+-!!8'0+,0'!(+2!0+(%<,/0/!/-2/$>(!0/!(%,-/1+!0+!0%7%',"2%'(M!
self.nome_do_widget['command']=self.event_handler 
;&/!7/2/7-+28(-%7/! %&8'2-/,-+!)*/,0'! (+!*(/!+(-+!82'7+(('!0+!/(('7%/30'!>!
)*+! 0+(-/! $+K! '! '*)+-'!-$-8/*! '-$-8/+! ,0'! 82+7%(/! (+2! 8/((/0'! 7'&'!/2<*&+,-'!0'!
+$+,-!&/,01+29!
@!+1+&81'!(+<*%,-+!7',;2',-/!/(!0*/(!&/,+%2/(!0+!/(('7%/30'!0+!+$+,-'(!)*+!
/<'2/!7',&+7+&'(9!!
 
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 22
from Tkinter import * 
class Janela: 
 def __init__(self,toplevel): 
 
 self.frame=Frame(toplevel) 
 self.frame.pack() 
 
 self.b1=Button(self.frame) 
 self.b1.bind("<Button-1>", self.press_b1) 
 self.b1.bind("<ButtonRelease>", self.release_b1) 
 self.b1['text'] = 'Clique em mim!' 
 self.b1['width'], self.b1['bg'] = 20, 'brown' 
 self.b1['fg']='yellow' 
 self.b1.pack(side=LEFT) 
 
 self.b2=Button(self.frame) 
 self.b2['width'], self.b2['bg'] = 20, 'brown' 
 self.b2['fg']='yellow' 
 self.b2.pack(side=LEFT) 
 
 self.b3=Button(self.frame, command=self.click_b3) 
 self.b3['width'], self.b3['bg'] = 20, 'brown' 
 self.b3['fg']='yellow' 
 self.b3.pack(side=LEFT) 
 
 def press_b1(self,event): 
 self.b1['text']='' 
 self.b2['text']='Errou! Estou aqui!' 
 def release_b1(self,event): 
 self.b2['text']='' 
 self.b3['text']='OOOpa! Mudei de novo!' 
 def click_b3(self): 
 self.b3['text']='Ok... Você me pegou...' 
 
instancia=Tk() 
Janela(instancia) 
instancia.mainloop() 
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 23
$>G'> !&$E*
!
@!*'-0'!0/!+()*+20/!7&/&/!*&!+$+,-!&/,01+2!0/!;'2&/!)*+!)"!7',&+78/&'(9!
X1%)*+!,+1+!(+&!('1-/2!'!*'-0'!0'!&'*(+!+!$'7Q!$+2"!)*+!'!-+1-'!0'!*'-0'!7+,-2/1!)"!>!
&'0%;%7/0'9!2'1-+!'!*'-0'!0'!&'*(+!+!'(! -+1-'(!&*0/20'!,'$/&+,-+9!@!&+(&'!,0'!
/7',-+7+!7'&!'!*'-0'!0/!0%2+%-/9!X1%)*+!,+1+!(+&!('1-/2!+!$'7Q!$+2"!)*+!,/0/!/7',-+7+!
/->!)*+!'!*'-0'!0'!&'*(+!(+)/!('1-'9!
!
,!< >*!3*/*3!4R$G*&>*&!&$G*
!
2?* %*D,&1> *!"#$%*
!
@! -%0<+-! 78/%P! >! *&! &+%'! 0+! 2+7'1&+2! +,-2/0/(! 0+! 0/0'(! 0'! *(*"2%'9! @(!
0/0'(! %,;'2&/0'(! 8+1'! *(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* 7 % 2 # 5 ! $ + * 24
*'20/(! +! '(!-%0<+-(! 0+,-2'! 0+1+! '7/('! 7',-2"2%'! '! *'-0'! ;%7/2%/! 7'1/0'! /'! 7/&8'!0+!
+,-2/0/!0+!0/0'(+9!
 
from Tkinter import * 
class Passwords: 
 def __init__(self,toplevel): 
 
 self.frame1=Frame(toplevel) 
 self.frame1.pack() 
 self.frame2=Frame(toplevel) 
 self.frame2.pack() 
 self.frame3=Frame(toplevel) 
 self.frame3.pack() 
 self.frame4=Frame(toplevel,pady=10) 
 self.frame4.pack() 
 
 Label(self.frame1,text='PASSWORDS', fg='darkblue', 
 font=('Verdana','14','bold'), height=3).pack() 
 
 fonte1=('Verdana','10','bold') 
 Label(self.frame2,text='Nome: ', 
 font=fonte1,width=8).pack(side=LEFT) 
 self.nome=Entry(self.frame2,width=10, 
 font=fonte1) 
 self.nome.focus_force() # Para o foco começar neste campo 
 self.nome.pack(side=LEFT) 
 
 Label(self.frame3,text='Senha: ', 
 font=fonte1,width=8).pack(side=LEFT) 
 self.senha=Entry(self.frame3,width=10,show='*', 
 font=fonte1) 
 self.senha.pack(side=LEFT) 
 
 self.confere=Button(self.frame4, font=fonte1, text='Conferir', 
 bg='pink', command=self.conferir) 
 self.confere.pack() 
 self.msg=Label(self.frame4,font=fonte1, 
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 25
 height=3,text='AGUARDANDO...') 
 self.msg.pack() 
 
 def conferir(self): 
 NOME=self.nome.get() 
 SENHA=self.senha.get() 
 if NOME == SENHA: 
 self.msg['text']='ACESSO PERMITIDO' 
 self.msg['fg']='darkgreen' 
 else: 
 self.msg['text']='ACESSO NEGADO' 
 self.msg['fg']='red' 
 self.nome.focus_force() 
 
instancia=Tk() 
Passwords(instancia) 
instancia.mainloop() 
!
$>G'> !&$E*
!
!
!!!=-(6*8,'#%36&,*?#*#4$-#,&;&/-&#8*# '+6*#,-#(-8D'#8*# '(*#' &+'8!
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 26
,!< >*3*/*3!@7!G*
!
@!@'8$'(! >!*&!-%0<+-! %&8'2-/,-8((%&'!8/2/!/!"2+/! 7%+,-8;%7/! +! +,<+,&/2%/9!
X'&! +1+! 8'0+&'(! ;/K+2! (%&*1/37+(!! 81'-/<+,(!! 0+(+,&'(!! 72%/2! ,'(('(! 82Y82%'(!
-%0<+-(!! +! /->! &+(&'! 8+)*+,/(! /,%&/37+(!! 2+(8+%-/,0'! /! $+1'7%0/0+! 0+!82'7+((/&+,-'! 0'! (+*! /&%<'!$X9! =&/<%,+!'! 7/,$/(! 7'&'!*&/!82/,7&+-/!',0+!$'7Q!
8'0+! 0+(+,&/2! '*)+-'(! 7'&'! 1%,&/(!! /27'(!! 7827*1'(! +! 8'18<','(! S! $',-/0+9! J)*%!
$+2+&'(!'(!82%,7%8/%(!-%8'(!0+!'*)+-'(!';+2+7%0'(!8+1'!7/,$/(!0'! ,%,-+2M!/27'!! 1%,&/!!
+1%8(+!!8'18<','!!2+-:,<*1'!+!-+1-'9!
/+;%,+.(+! *&! X/,$/(! 7'&'! (+! 0+;%,+! )*/1)*+2! '*-2'! -%0<+-9! :1+! -+&! /(!
&+(&/(!'837+(!0+!7',;%<*2/30'!)*+!*'-7+(!+! 1/*+1(!! %,71*(%$+!0*/(!)*+!$+2+&'(!,'!
82Y1%&'!+1+&81'M!@,! +! $%(*%9!X'&!/!'830'!@,!8'0+&'(!+(8+7%;%7/2!/!+(8+((*2/!0/!
*'20/!0+!*&!-%0<+-!!+&!8%1+1(9!@$%(*%!!8'2!(*/!$+K!!0%K!/'! %,-+282+-/0'2!7'&'!0+$+!
/8/2+7+2! '! 8',-+%2'! 0'! &'*(+! )*/,0'! +1+! +(-%$+2! ('*2+! '! -%0<+-9! J1<*,(! $/1'2+(!
0%(8',8$+%(!(0'!A+ $%(*%!! &% .-!!,*/!!,*/@*5!! ).-$%!+! /'%;-/9!20'!GG!'837+(!0+!7*2('2!
$"1%0/(! 8/2/! )*/1)*+2! -%0<+-! +! $'7Q! 8'0+! 7',&+7+2! -'0/(! +1/(! /-2/$>(! 0'(! 1%$2'(!
2+7'&+,0/0'(!/'!;%,/1!0+(-+!rY0*1'9!
<'!+1+&81'!$'7Q!8+27+*+!)*+!,0'!('&'(!+(72/$'(!0'!7',-Q%,+2!)%'+-9!O"!)*+!
(Y!0+;%,%&'(!0'%(!-%0<+-(!(%&81+(!!8*0+&'(!72%/.1'(!0%2+-/&+,-+!,/!)/,+1/!-'8.1+$+19!
J)*%!$'7Q!/82+,0+!0*/(!,'$/(!7'2+(!8/2/!+,2%)*+7+2!'!(+*!$'7/**1"2%'9!
 
from Tkinter import * 
class Kanvas: 
 def __init__(self,raiz): 
 
 self.canvas1 = Canvas(raiz, width=100, height=200, 
 cursor='X_cursor', bd=5, 
 bg='dodgerblue') 
 self.canvas1.pack(side=LEFT) 
 self.canvas2 = Canvas(raiz, width=100, height=200, 
 cursor='dot', bd=5, 
 bg='purple') 
 self.canvas2.pack(side=LEFT) 
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 27
instancia=Tk() 
Kanvas(instancia) 
instancia.mainloop() 
 
$>G'> !&$E*
!
@!+(8/3'!7%,K/!)*+!(+8/2/!'(!7:,$/(+(!+!0"!*&/!;'1</!+,-2+!+1+(!+!/!*'20/!
0/!)/,+1/!>!0+$%0'!S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%2+-/&+,-+!,'(!
-+2&'(! 0'! (%(-+&/! 0'! X/,$/(! /82+(+,-/&! &/%(! '*! &+,'(! /! &+(&/! 0%;%7*10/0+W!
+(7'1&/!/!)*+!&/%(!/<2/0/29!
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 29
5?* 2,@)!G*
!
J!(%,-/1+!8/2/!0+(+,&/2!*&/!1%,&/!,*&!7/,$/(!>!
self.nome_do_canvas.create_line(x1, y1, ...., xn, yn) 
:(-/!1%,&/!7'&+3/!,'!8',-'!'1>!!%>+!!(+<*+!/->!'!8',-'!'1@!!%@+!!'1E!!%E+!+!
/((%&! 8'2! 0%/,-+! /->! -+2&%,/2! +&! '1,!! %,+9! @(! 8',-'(! 8'0+&! (+2! 8/((/0'(!
%('1/0/&+,-+!!'*!+&!<2*8'(!0+,-2'!0+!-*81/(!'*!1%(-/(!!0+((+!)+%-'M!
create_line(x1, y1, x2, y2, x3, y3, x4, y4, ......)!'*!
create_line((x1, y1), (x2, y2), (x3, y3), (x4, y4), ......)!'*!
create_line((x1, y1, x2, y2), (x3, y3, x4, y4), ......)!! +! -'0/(!
+(-/(!-*81/(!-/&*>&!8'0+2%/&!(+2!1%(-/(9!=(-'!;/7%1%-/!%&+,(/&+,-+!'!-2/*/1&'!)*/,0'!
'(!8',-'(!0+!)*+!0%(8'&'(!)"!(0'!-*81/(!'*!1%(-/(9!@*!(+)/!!8/2/!0+(+,&/2!*&/!1%,&/!
+,-2+!$>!X!'1>!!%>+!+!$@!X!'1@!!%@+!!*/(-/!;/K+2! %-'/-+.&8--$>C!$@/9!2+&!+(-+!2+7*2('!!
-+28/&'(!)*+!*(/2!/!%,-2/<"$+1!(+,-+,3/! %-'/-+.&8--$>_I`C!$>_>`C!$@_I`C!$@_>`/999!
J8Y(!+(-/!(+)aQ,7%/!0+!8',-'(!0%K+,0'!8'2!',0+!/!1%,&/!0+$+2"!(+<*%2!!/%,0/!
8'0+&!$%2!/1<*&/(!'837+(!0+!7',;%<*2/30'9!J(!82%,7%8/%(!(0'!,&,/D!!)*+!0+-+2&%,/!/!
+(8+((*2/!0/!1%,&/!+!)&..!!8/2/!+(8+7%;%7/2&'(!(*/!7'29!
<'! +1+&81'!! &"! *&/! 1%,&/! )*+! 7'&+3/! ,'! 7+,-2'! 0'! 7/,$/(9!;&! -2+7&'!0+!
7'&82%&+,-'!>I!>!0+(+,&/0'!,/!0%2+30'!)*+!'!*(*"2%'!%,0%7/2!,'(!*'-7+(9!!<'-+!)*+!
0+;%,%&'(!*&!/-2%**-'!8/2/!%,(-:,7%/!0+! ,!!(-.)6.'(/!!)*+!(+2$%2"!8/2/!<*/20/2!/!41-%&/!
8'(%30'!/((*&%0/!8+1/!1%,&/!+!%,72+&+,-/.1/!&/%(!;/7%1&+,-+9!
2+! $"2%'(! -%0<+-(! 7'&8/2-%1&/20'! /(!&+(&/(! '837+(! 0+! 7',;%<*2/30'!! $'7Q!
8'0+! (/1$/.1/(! -'0/(!,*&!0%7%',"2%'! +!8/((/.1'! 7'&'!/2<*&+,-'!,/!0+;%,%30'!0+(-+(!
-%0<+-(9! $'2! 41-%&'!! ,'-+! )*+! '20+,/&'(! )*+! )*/,0'! '! 8',-+%2'! 0'! &'*(+! +(-%$+2!
('*2+!'!7/,$/(!!0+$+2"!/8/2+7+2!/!/&8*1&+-/!','/ D+9!
 
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 30
 
from Tkinter import * 
class Linhas: 
 def __init__(self,raiz): 
 self.canvas = Canvas(raiz, width=400, height=400, 
 cursor='watch', bd=5) 
 self.canvas.pack() 
 self.frame=Frame(raiz) 
 self.frame.pack() 
 
 self.last=[200,200] 
 
 configs={'fg':'darkblue', 'bg':'ghostwhite', 'relief':GROOVE, 
 'width':11,'font':('Verdana','8','bold')} 
 self.b1=Button(self.frame, configs, 
 text='Esquerda', command=self.left) 
 self.b1.pack(side=LEFT) 
 self.b2=Button(self.frame, configs, 
 text='Para cima', command=self.up) 
 self.b2.pack(side=LEFT) 
 self.b3=Button(self.frame, configs, 
 text='Para baixo', command=self.down) 
 self.b3.pack(side=LEFT) 
 self.b4=Button(self.frame, configs, 
 text='Direita', command=self.right) 
 self.b4.pack(side=LEFT) 
 
 def left(self): # Desenha um segmento para a esquerda 
 x, y = self.last[0]-10, self.last[1] 
 self.canvas.create_line(self.last, x, y, fill='red') 
 self.last=[x,y] 
 def up(self): # Desenha um segmento para cima 
 x, y = self.last[0], self.last[1]-10 
 self.canvas.create_line(self.last, x, y, fill='yellow') 
 self.last=[x,y] 
 def down(self): # Desenha um segmento para baixo 
 x, y = self.last[0], self.last[1]+10 
 self.canvas.create_line(self.last, x, y, fill='blue') 
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 31
 self.last=[x,y] 
 def right(self): # Desenha um segmento para a direita 
 x, y = self.last[0]+10, self.last[1] 
 self.canvas.create_line(self.last, x, y, fill='purple') 
 self.last=[x,y] 
 
instancia=Tk() 
Linhas(instancia) 
instancia.mainloop() 
*
$>G'> !&$E!/!#;=!2+(*1-/,-+!>!<2/,0+!0+&/%(!8/2/!(+2!&'(-2/0/!/)*%!+!(*/!
/8/2Q,7%/!,0'!>!-0'!%,(-2*-%$/!)*/,-'!(+*!;*,7%',/&+,-'9!=&81+&+,-+!+(-+!+1+&81'!+!
$+)/! )*/,-'(! 0+(+,&'(! %,-+2+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 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 32
$'0+&'(!/0%7%',/2!-+1-'(!/'(!7/,$/(!0+!*&/!&/,+%2/!*+&!(%&81+(9!2%,-/1+M!
self.nome_do_canvas.create_text(x, y) 
@!-+1-'!!0+;%,%0'!8+1/!'830'! /-5/!!(+2"!8'(%7%',/0'!+&!'1!%+9!=&/<%,+!)*+!'!
-+1-'!/!(+2!&'(-2/0'!+(-+)/!7',-%0'!,*&!2+-:,<*1'!!7'&'!,/!;%<*2/!/*/%1'9!
!
J-2/$>(! 0/! '830'! '8 D*%!! 8'0+&'(! +(8+7%;%7/2! )*/1! 0+(-+(! 8',-'(! 0'!
2+-:,<*1'!+(-"!('*2+!/!7''20+,/0/!'1!%+!)*+!%,;'2&/&'(9!/%</&'(!)*+!/,7&'2X2J!+!
0+;%,%&'(!/!8'(%30'!0'!-+1-'!+&!'>II!!>II+9!J((%&!!/!*'20/!+()*+20/!%,;+2%'2!0'!-+1-'!
;%7/2"!+&!'>II!!>II+9!@!$/1'2!8/020'!0+!'8 D*%!>!X:< :69!
J! '830'! )*8/! )*+! )"! 7',&+7+&'(! 0'(! *'-7+(! +! 1/*+1(! -/&*>&! 8'0+! (+2!
/81%7/0/!/)*%!!+!/!7'2!0'!-+1-'!8'0+!(+2!&*0/0/!7'&!/!'830'!)&..9!!
J!&+,'(!)*+!(+)/!0+;%,%0'!*&!$/1'2!8/2/!/!'830'!,&,/D!!'!-+1-'!(+2"!+(72%-'!
-'0'! +&! *&/! 4,%7/! 1%,&/9! X'&!,&,/D! 0+-+2&%,/&'(! '! 7'&82%&+,-'!&"1%&'!)*+! /(!
1%,&/(! 0+! -+1-'! 8'0+&! /((*&%29! 2+! ,+7+(("2%'!! /! (+,-+,3/! >! )*+*2/0/! +,-2+! /(!
8/1/$2/(! 8/2/! 7*&82%2! +(-/! 7',;%<*2/30'9! Q*/,0'! %(-'! '7'22+!! 8'0+! (+2! %,-+2+((/,-+!
0+;%,%2!)*+!/1%,&/&+,-'!/(!1%,&/(!0+$+&!/((*&%2!+,-2+!(%9!J!'830'!)*+!0+-+2&%,/!%(('!
>! Z$(/&)P!! 7*)'(! $/1'2+(! (0'! 5:F ! '/1%,&/0/(! S! +()*+20/! ?! '! $/1'2! 8/020'+!! X:< :6!
'7+,-2/1%K/0/(+!+!6=#B !'/1%,&/0/(!S!0%2+%-/+9!
<'! 82Y1%&'! +1+&81'! *(/&'(! /! ->7,%7/! 0+! 7',$+2(0'! 7/2-+(%,/,/.7/,$/(9!
$2+7%(/&'(!0+(+,&/2!*&!8+,-"<','!*(/,0'! %-'/-+6*.P;*8!+!,'(!8/2+7+*!&/3/,-+!-+2!
)*+!8+,(/2!,/(!7''20+,/0/(!0/(!7%,7'!8',-/(!+&!-+2&'(!0'!X/,$/(9!r+1&'2!82')+-/2!'!
8+,-"<','!7'&'!+(-/&'(!/7'(-*&/0'(!+!0+8'%(! 7',$+2-+2!'(!$/1'2+(9!P+)/!'!82')+-'!
+&!7''20+,/0/(!7/2-+(%/,/(M!
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 33
!
:(-+! 8+,-"<','! (+2"! 0+(+,&/0'!,*&! 7/,$/(! 0+! /1-*2/! @II9!/+((/! ;'2&/!! /!
7''20+,/0/!'>II!!>I+!-+2"!)*+!(+2!%&81+&+,-/0/!7'&'!'>II!!@II.>I+!X!'>II!!>HI+!!+!
/((%&! 8'2! 0%/,-+9! X1/2'! )*+! ,0'! ;%K+&'(! -'0/(! +(-/(! 7',-%,&/(! 8/2/! 7/0/! 8/2!
'20+,/0'W! (%&81+(&+,-+! (/1$/&'(! /! /1-*2/! @II! ('*! '! ,'&+! './$%'! +! (%&81+(&+,-+!
+(72+$+&'(!,'((/(!7''20+,/0/(!7/2-+(%/,/(!7'&'!'>II!!'./$%'!?!>I+!!8'2!+1+&81'9!
<+(-+! 82'<2/&/! >! %&8'2-/,-+! '*(+2$/2! )*+! /-2%**8&'(! -'0/! /! (+,-+,3/!
(-.)6 '8$'(6 %-'/-+6*.P;*8!/!*&!,'&+!!6*.!!8/2/!/<%1%K/2!'!*('!0+(-+!&>-'0'9!
!
from Tkinter import * 
class SPFC: 
 def __init__(self,raiz): 
 self.canvas=Canvas(raiz, width=200, height=200, bg='dodgerblue') 
 self.canvas.pack() 
 
 altura = 200 # Altura do canvas 
 
 pol=self.canvas.create_polygon 
 ret=self.canvas.create_rectangle 
 pol(100, altura-10, 
 10, altura-145, 
 10, altura-190, 
 190, altura-190, 
 190, altura-145, 
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 34
 100, altura-10, fill='white') 
 ret(15, altura-150, 185, altura-185, fill='black') 
 pol(20, altura-140, 
 95, altura-140, 
 95, altura-30, 
 20, altura-140, fill='red') 
 pol(105, altura-30, 
 105, altura-140, 
 180, altura-140, 
 105, altura-30, fill='black') 
 self.canvas.create_text(100, altura-167.5, text='S P F C', 
 font=('Arial','26','bold'), 
 anchor=CENTER, fill='white') 
 
instancia=Tk() 
SPFC(instancia) 
instancia.mainloop() 
!
$>G'> !&$E*
!
!O"! $'*! /$%(/,0'! )*+! ,0'! ('*! (0'.8/*1%,'9! 2%&81+(&+,-+! '! 1'<'-%8'! &+!
8/2+7+*!;"7%1!0+!0+(+,&/29!J1%"(!!/7&'!)*+!*&!-'27+0'2!0+!$+20/0+!,0'!0+(+,&/2%/!(+*!
1'<'-%8'!0'!7'2/30'!-0'!0+(82'8'27%',/1999!
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % *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*1'!)*+!7',-+20'!'!/27'!0+$+&!(+2! %,;'2&/0/(!!&/(!(0'!/(!'837+(!
0+! 7',;%<*2/30'! )*+! $0'! 0+-+2&%,/2! /! /8/2Q,7%/! 0'! /27'9! X',(%0+2+! '! 7+,-2'! 0'!
2+-:,<*1'!7'&'!'!7+,-2'!0+!7*2$/-*2/!0'!/27'M!
!
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 36
$'2! &+%'! 0/! '830'! (/'%/!! 0/0/! +&! <2/*(! /! 8/2-%2! 0'! +%1'! 1! 8'(%-%$'! +! +&!
(+,-%0'!/,-%.&'2"2%'!!0+-+2&%,/&'(!)*/1!/! 1%,&/!/!8/2-%2!0/!)*/1!'!/27'!7'&+3/!/!(+2!
0+(+,&/0'9!:1+&81'M!,/!;%<*2/!/7%&/!!;/28/&'(!(/'%/XCI9!
J!'*-2/!'830'!;*,0/&+,-/1!>!-5/-8/!!0/0/!+&!<2/*(!/!8/2-%2!0/!1%,&/!0+!%,87%'!
+!+&!(+,-%0'!/,-%.&'2"2%'!!8/2/!0+-+2&%,/2!/->!)*+!1%,&/!'!/27'!(+2"!0+(+,&/0'9!P+)/!
,/!82Y1%&/!;%<*2/!'!+1+&81'!*(/,0'!-5/-8/XHI!+!'!/27'!)"!0+(+,&/0'9!
!
$'2! 41-%&'!! &"! /! '830'! (/P.-! 8/2/! 0+-+2&%,/2! '! +(-%1'! 0'! /27'9! @(! $/1'2+(!
8'0+&!(+2!J6X!!XB@6/!+!$=:25=X:!''!8/020'+9!
!
@! +1+&81'! (+<*%,-+! >! *&! 82'<2/&%,&/! 8/2/! 72%/,3/(! /82+,0+2+&!
8'27+,-/<+,(!7'&!-'2-/(9!:(-/&'(!/7'(-*&/0'(!/!(/1$/2!'!$/1'2!0/!/1-*2/!0'!7/,$/(!
,*&! ,'&+! 8/2/! ;/7%1%-/2! ,'(('! (+,('! 0+! 7''20+,/0/(9! X'&'! +(-+! $/1'2! -/&*>&! >!
*(/0'! 0+,-2'! 0+! *&! +$+,-! &/,01+2!!&+1&'2! -2/,(;'2&/2! +(-/! /1-*2/! ,*&!/-2%**-'! 0/!
%,(-:,7%/!8'2!&+%'!0+!(-.)6'./$%'9!<0'!0+%1+!0+!,'-/2!-/&*>&M!
• J!-*81/!7',-+,0'!/(!7',;%<*2/37+(!0+!;',-+!)*+!(+2%/&!*(/0/(!+&!$"2%'(!
-%0<+-(! ;'%! (/1$/! ('*! *&! ,'&+!! (Y! 8/2/! ,0'! -+2&'(! )*+! 2++(72+$+.1/! -'0/!
&'2/W!• !@!$/1'2!0+!8'27+,-/<+&!6!0/0'!8+1'!*(*"2%'!>!7',$+2-%0'!+&!-+2&'(!0+!
8'27+,-/<+&! 0'! 7827*1'! ')*/,-'(! <2/*(! +)*%$/1+&! /! 6! 8'2! 7+,-'! 0+! ECIbV+!
0+,-2'! 0'! +$+,-! &/,01+29! $/2/! %(('! >! ,+7+(("2%'! 7',$+2-+2! +&! ;1'/-! /! (-2%,<!
%,;'2&/0/9!<*,7/!(+!+()*+3/!0+!)*+!)*/1)*+2!$/1'2!0%<%-/0'!,'!-%0<+-!:,-2%!
>!*&/!(-2%,<9W!
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 37
• 5'<'! 0+8'%(! 0+! '! /27'! (+2! 0+(+,&/0'!! '! +$+,-! &/,01+2! 2+-'2,/! '! ;'7'!
8/2/!'!7/&8'!0+!0/0'(9!
 
# -*- coding: cp1252 -*- 
from Tkinter import * 
class Fatias: 
 def __init__(self,raiz): 
 self.canvas=Canvas(raiz, width=200, height=200) 
 self.canvas.pack() 
 self.frame=Frame(raiz) 
 self.frame.pack() 
 
 self.altura = 200 # Altura do canvas 
 
 self.canvas.create_oval(25, self.altura-25, 
 175, self.altura-175, 
 fill='deepskyblue', outline='darkblue') 
 fonte=('Comic Sans MS', '14', 'bold') 
 Label(self.frame, text='Fatia: ', 
 font=fonte, fg='blue').pack(side=LEFT) 
 self.porcentagem=Entry(self.frame, fg='red', 
 font=fonte, width=5) 
 self.porcentagem.focus_force() 
 self.porcentagem.pack(side=LEFT) 
 Label(self.frame, text='%', 
 font=fonte, fg='blue').pack(side=LEFT) 
 self.botao=Button(self.frame, text='Desenhar', 
 command=self.cortar, font=fonte, 
 fg='darkblue', bg='deepskyblue') 
 self.botao.pack(side=LEFT) 
 
 def cortar(self): 
 
 arco=self.canvas.create_arc 
 fatia=float(self.porcentagem.get())*359.9/100. 
 arco(25, self.altura-25, 
 175, self.altura-175, 
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 38
 fill='yellow', outline='red', 
 extent=fatia) 
 self.porcentagem.focus_force() 
 
instancia=Tk() 
Fatias(instancia) 
instancia.mainloop() 
*
$>G'> !&$E*
!
<"# $%&'("# ")%*"# +,*-.# -# /(-&("*"#*-.0("12-# '*"# $"0%"# 2,# ACc#2"# 0-(0"6#
P,)"#)-*-#".#9,0(".#.0-#&("12,.#,#)-9-(%2".#;#0'2-#2%(,)%-1"2-#"-#/4*9%)-#%1$"10%9#>',#
'."(%"#,.0"##;=6#
Y# '*"# /,1"# >',# 0-2"# +,K# >',# "# &,10,# >',%("# (,/(,.,10"(# '*"# 1-+"#
/-(),10"&,*!#0,1&"#>',#$,)&"(#,.0"#)"1,9"#,#"*(%(#-'0("6#F-*-#.,("#>',#$"(8"*-.#/"("#
"/"&"(#-#"()-#>',#(,/(,.,10"#,.."# $"0%"#2,#ACc#,#2,.,1&"(#-'0(-#)-*#/-(),10"&,*#
>'"9>',(V##
#
#
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 39
9?* :=>=?-,!4=? $*&=*$@L= $I*&$*3!?7!I*
#
J..%*#>',#'*#-*),0-#K#)(%"2-#1'*#)"1+".!#(,),*,#"'0-*"0%)"*,10,#'*#=/#;#
'*#14*,(-#%10,%(-#/"("#2%$,(,1)%".9-#2-.#2,*"%.6#N#!.K.%*-#-*),0-#2,.,1&"2-#0,*#=/#
!6# Q'"12-# .,# %1.,(,# '*# -*),0-# 1'*# )"1+".!# ,9,# .,# 2%./7,# "#$%&# -.# 2,.,1&"2-.#
"10,(%-(*,10,6#J..%*!#-.#*,1-(,.#=/.#/,(0,1),*#"-.#-*),0-.#>',#,.00-#*"%.#/(Q1%*-#
2-#$'12-#2-#)"1+".#'-#L*"),&(-'12M+X#
#
N# )"1+".# -$,(,),# 2-%.# *K0-2-.# *'%0-# %*/-(0"10,.# /"("# &,(,1)%"(# .,'.#
-*),0-.X# '(!)++,,-//#>',#(,0-(1"#'*"#0'/9"#)-*#-#=/#2,#0-2-.#-.#-*),0-.#,#)&,&0&-Z>!#
Z@!#6666!#Z1/#>',#"/"&"#2-#)"1+".#-.#-*),0-.#2,#=/1A)!1A0!#666!1A!6#\.0,#490%*-#*K0-2-#
K#)"/"K#2,#(,),*,(#-.#=/.#,*#$-(*"#2,#.0(%1&.#2,#%10,%(-.!#%.0-#K!#L>M!#L@M!#,0)6#
<'*# )"1+".# )-*# 2,K,1".# 2,# -*),0-.!# "9&'*# /-2,# 0,(# (,9,+:1)%"# &("12,#
2,*"%.# /"("# .,(# %2,10%$%)"2-# .%*/9,.*,10,# )-*# '*# 14*,(-6# $-(# %..-!# 0"**K*#
/-2,*-.# %2,10%$%)"(# -.# -*),0-.# /-(# *,%-# 2,# .0(%1&.# )&"*"2".# 0+5"6# J# (%&-(!# 0+5# .,#
)-*/-(0"# )-*-# '*"# -/30-# 2,# )-1$%&'("30-# 2,$%1%2"# 1-# %1.0"10,# ,*# >',# -.#-%2&,0.#
.0-#)(%"2-.6#2,#+-)b#>',(#)(%"(#'*#)8()'9-#,#)&"*".9-#2,#L*-9">M!#*".0"#$"K,(#
self.nome_do_canvas.create_oval(coord., opções, tag = "bola1") 
J# 0+5# 2,# '*# -*),0-# 0"**K*# /-2,# .,(# '."2"# )-*-# "(&'*,10-# 2-# *K0-2-#
)&,&0&!#"9K*#2-#=/6#
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 40
/%.)'..0-# %*/-(0"10,X# >'"12-# 2,.,1&"*-.# '*"# 9%1&"!# .,("# >',# )"2"#
.,&*,10-#(,),*,#'*#=/!#-'#"#9%1&"#0-2"#/-..'%#"#*,.*"#%2,10%$%)"30-V#;*"#$-(*"#2,#
10-# ,(("(# 1'1)"# ,.0,# 0%/-# 2,# >',.00-# K# 9,**("(..,# 2,# >',# )"2"# "/9%)"30-# 2,# '*#
*K0-2-# )-*-# %&+0&+,(!&# ,# %&+0&+7#,85#!# &,("# .-*,10,# '*# =/# '-'# 0"&!# .,# +-)b#
>'%.,(+#>',#1-*,%"#0-2"#"#.,>ab1)%"#2,#.,&*,10-.!#/-(#*"%-(#>',#.,)"6#$-(#%..-#0-*,#
)'%2"2-#"-#)(%"(#'*"#9%1&"#(,/9,0"#2,#.,&*,10-.#)-*#'*"#41%)"#"/9%)"30-#2-#*K0-2-#
&,("2-(!#/-(>',#-#*K0-2-#)&,&0&#"/"&"(%"#0-2-.#,9,.9#
<-#/(Q1%*-#,1,*/9-#$"K,*-.#'*#(,9Q&%-#2,#+,(2"2,9#\9,#'."#'*"#$'130-#2-#
*Q2'9-# 0(9&# /"("# ."*,(# >',# &-(".# .0-# 1-# .,'# )-*/'0"2-(!# ,# *-.0("# %..-# 1'*"#
.%*'9"30-# '$,%"!# K# +,(2"2,+# 2,# '*# ("2%-.(,9Q&%-6# P,)"# )-*-# "# -/30-# #$0,(!&1X# dd# K#
'."2"#/"("#2,0,(*%1"(#>',#"#*-(2"#2".#$%&'(".#.,)"#0("1./"(,10,6#
 
# -*- coding: cp1252 -*- 
from Tkinter import * 
from time import localtime 
class Horas: 
 def __init__(self,raiz): 
 
 self.canvas=Canvas(raiz, width=200, height=100) 
 self.canvas.pack() 
 self.frame=Frame(raiz) 
 self.frame.pack() 
 
 self.altura = 100 # Altura do canvas 
 
 # Desenho do relógio----------------------------- 
 pol=self.canvas.create_polygon 
 ret=self.canvas.create_rectangle 
 self.texto=self.canvas.create_text 
 self.fonte=('BankGothic Md BT','20','bold') 
 pol(10, self.altura-10, 
 40, self.altura-90, 
 160, self.altura-90, 
 190, self.altura-10, fill='darkblue') 
 pol(18, self.altura-15, 
 45, self.altura-85, 
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 41
 155, self.altura-85, 
 182, self.altura-15, fill='dodgerblue') 
 ret(45, self.altura-35, 
 90, self.altura-60, fill='darkblue', outline='') 
 ret(110, self.altura-35, 
 155, self.altura-60, fill='darkblue', outline='') 
 self.texto(100, self.altura-50, text=':', 
 font=self.fonte, fill='yellow') 
 # Fim do desenho do relógio----------------------- 
 
 self.mostrar=Button(self.frame, text='Que horas são?', 
 command=self.mostra, 
 font=('Comic Sans MS', '11', 'bold'), 
 fg='darkblue', bg='deepskyblue') 
 self.mostrar.pack(side=LEFT) 
 
 def mostra(self): 
 
 self.canvas.delete('digitos_HORA') 
 self.canvas.delete('digitos_MIN') 
 HORA = str( localtime()[3] ) 
 MINUTO = str( localtime()[4] ) 
 self.texto(67.5, self.altura-50, text=HORA, fill='yellow', 
 font=self.fonte, tag='digitos_HORA') 
 self.texto(132.5, self.altura-50, text=MINUTO, fill='yellow', 
 font=self.fonte, tag='digitos_MIN') 
 
instancia=Tk() 
Horas(instancia) 
instancia.mainloop() 
*
*
*
*
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 &' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 42
$=I'> !&$E*
#
Q'"12-# /,(&'10"*-.# "# &-("!# K# 1,),.."(%-# >',# -# ,+,10# &"129,(#
)-((,./-12,10,# "/"&',# -# +"9-(#*-.0("2-!# .,10-# -.# 0,10-.# $%)"(%"*# .-*(,/-.0-.6# $-(#
%..-!#2,*-.#'*#1-*,#''*"#0"&+#"-.#0,10-.#)-((,./-12,10,.#S.#&-(".#,#"-.#*%1'0-.6#
/,.."# $-(*"!# .-*-.# )"/"K,.# 2,# "/"&"(# .-*,10,# ,.0,.# 2-%.# -*),0-.!# .,*# 0,(# >',#
(,2,.,1&"(#0-2-#-#("2%-.(,9Q&%-!#>',#K#)-*/-.0-#2,#+"(%-.#/-98&-1-.!#(,0:1&'9-.#,#'*#
0,10-#>',#*-.0("#-.#2-%.#/-10-.#,10(,#".#&-(".#,#-.#*%1'0-.#',*#"*"(,9-#1"##;=+6#
#
!##;1 <+0#1 !&""+1 =!"1 B1 4$&1 B# '1 0&91 4$&1 &"7&%+%1 $919(!$0#1 7+%+1 #1
B+,#%19$)+%6661=&)&"&!<&1#1%&,C5(#17+%+19#"0%+%1<#%+"/19(!$0#"1&1"&5$!)#"G#
!# # D31 7&!"+!)#1 +E1 #9#1 B# '1 &" %&B&%(+1 +1 =!"1 )&1 $91 %&,C5(#1 )&1
7#!0&(%#"61*L#17%& ("+1(97,&9&!0+%17#%4$&1<31$91&5&% E (#1+)(+!0&14$&17&)&1
(""#/19+"1B31"&7+%+!)#1!+1"$+1 +$&N+1#"1(!5%&)(&!0&"1!& &""3%(#"G#
#
N.#-%2&,0.#)-*-#*-07,.#,#,10(%,.#,.00-#/"("#-#$("*,#"..%*#)-*-#-.#-*),0-.#
2,#2,.,1&-#,.00-#/"("#-#)"1+".6#=..-#$"K#2-#F"1+".#'*#)-10b%1,(#2,#)-*/-(0"*,10-#
.,*,9&"10,#"-# $("*,!# %1)9'.%+,#-# $-)-#2,# 0,)9"2-#10-#/".."#/-(#,9,6#<-#,10"10-!#/-(#
*,%-#2"#-/30-#2,#)-1$%&'("30-#0+O&'# $"X>!#/-2,*-.#%1)9'%.9-#1"#9%.0"#2-.#-%2&,0.#/-(#
-12,#-#$-)-#/".."("6#J..%*#/-2,*-.#"0(%*'%(#,+,10-.#2,#0,)9"2-#.-*(,#'*#)"1+".!#/-(#
,1,*/9-!#/"("#*-+,(#'*#2,#.,'.#-*),0-.#/"("#"#2%(,%0"#>'"12-#-#'.'"(%-#/(,..%-1"(#
_→`6#
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 43
Q',(#2%K,(#>',#K#/-..8+,9#*-+,(#'*#-*),0-#2-#F"1+".VVV#$-%.#K666#N#F"1+".#
/-..'%#'*#*K0-2-!#9#B&-0"&#-'#=//# %1)Z/# %1)e/!#>',#2,.9-)"#-#-*),0-#)')"#0"&#-'#=/#
$-%#2"2"#2,#'*"#/-.%30-#'Z!#e+#/"("#'*"#1-+"#/-.%30-#'Z#[#%1)Z!#e#[#%1)e+6##
N/"999#<0-#+"*-.#1-.#,.>',),(#>',#-#.%.0,*"#2,#)--(2,1"2".#2-#F"1+".#K#
2,# )"*,3"# /"("# *"%1-9# ;*# %1)(,*,10-# e# /-.%0%+-# $"(%"# -# -*),0-# )&" &%# 1-# )"1+".# ,#
1-..-# )K(,*(-# )"(0,.%"1-# /%("(6# 2,# +-)b# >'%.,(# >',# -# -*),0-# "$$+# (! F# ,*# +,K# 2,#
2,.),(#,.0,#+"9-(!#*".0"#%1$-(*"(#'*#+"9-(#1,&"0%+-#/"("#,.0,#%1)(,*,10-6#
N# /(Q1%*-# ,1,*/9-#*-.0("# "%12"# -#*K0-2-# '# $"-0"&# -'# =//!# # )-*# -# >'"9#
/-2,*-.# /".."(# -# $-)-# /"("# '*# -*),0-# 2-# )"1+".6# N*.,(+,# 0"**K*# '*"# 0K)1%)"#
$"10".0%)"#2,#L"&('/"(M#-*),0-.X#.,#"0(%*'%(*-.#"#*,.*"#0"&#"#+"(%-.#-*),0-.!#>'"9>',(#
"30-#,1,)'0"2"#.-*(,#"#0"&#.,("#.,10%2"#/-(#0-2-#-#&('/-#2,#-*),0-.6#
 
from Tkinter import * 
class Pacman: 
 def __init__(self, raiz): 
 self.canvas=Canvas(raiz, height=200, width=200, 
 takefocus=1, bg='deepskyblue', 
 highlightthickness=0) 
 self.canvas.bind('<Left>', self.esquerda) 
 self.canvas.bind('<Right>', self.direita) 
 self.canvas.bind('<Up>', self.cima) 
 self.canvas.bind('<Down>', self.baixo) 
 self.canvas.focus_force() 
 self.canvas.pack() 
 
 # Desenho da carinha---------------------------------- 
 self.canvas.create_oval(90, 90, 110, 110, 
 tag='bola', fill='yellow') 
 self.canvas.create_oval(93, 100, 98, 95, 
 tag='bola', fill='blue') 
 self.canvas.create_oval(102, 100, 107, 95, 
 tag='bola', fill='blue') 
 self.canvas.create_arc(92, 87, 108, 107, tag='bola', 
 start=220, extent=100, style=ARC) 
 # Fim do desenho da carinha---------------------------- 
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 44
 def esquerda(self, event): self.canvas.move('bola', -10, 0) 
 def direita(self, event): self.canvas.move('bola', 10, 0) 
 def cima(self, event): self.canvas.move('bola', 0, -10) 
 def baixo(self, event): self.canvas.move('bola', 0, 10) 
 
instancia=Tk() 
Pacman(instancia) 
instancia.mainloop() 
#
$=I'> !&$E*
#
J#-/30-#<(5<,(5<00<( O!&""#/-2,#.,(#"/9%)"2"#"#>'"9>',(#-%2&,0#,#.,(+,#/"("#
2,0,(*%1"(#"#,./,..'("#2"#9%1&"#2">',9,#(,0:1&'9-#>',#*-.0("#>',#-#-%2&,0#,.0"#,*#
$-)-6#<,.0,#)"1+".!#2%K,*-.#>',#"#,./,..'("#2,.."#9%1&"#K#K,(-#/"("#,+%0"(#>',#"#.'"#
)-(#/"2(0-#'/(,0-+#,.0("&"..,#"#"/"(b1)%"#2"##;=6#\**-("#-#(,0:1&'9-#10-#"/"(,3"!#-#
)"1+".#">'%#,.0"#.,*/(,#,*#$-)-6#
 "10-# "# (-.0-# "*"(,9-#>'"12-#-.#-9&-.#"K'%.# ,# "#*-)"#2,.."# )"(%1&"# $-("*#
"0(%*'82-.# S# *,.*"# 0"&# L*-9"M6# J..%*!# -.# ,+,10# &"129,(.# /-2,*# *-+,(# 0-2-# -#
)-1)'10-#2,#'*"#+,K#.Q!#.%*/9,.*,10,#.,#(,$,(%12-#"#,.."#0"&6#
J0,130-9#N#'.-#)-10%1'"2-#2-#)-**"12#*%12%1&#/-2,#1-.#$"K,(#,.>',),(#2,#
>',# >'"12-#'."*-.# -# /(-),..-# 2,# ,+,10# *%12%1&# '/-(#*,%-# 2-#*K0-2-#$(!)+# .-*-.#
-*(%&"2-.# "# /".."(# -# -*),0-# &B&!0## )-*-# "(&'*,10-# 2-.# ,+,10#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(&'("N*81%*"!# <&(5<0G"90'("N*81%*"/# 2,0,(*%1"# >',# "# )"1,9"# 10-#
0,1&"#2%*,1.7,.#*,1-(,.#>',#".#2"2".6# =.0-#/-2,#.,(#40%9#/"("#,+%0"(#>',#-#'.'"(%-#
(,2%*,1.%-1,#"#)"1,9"#,#,.)-12"#")%2,10"9*,10,#"9&'*#-%2&,06#$-(#$%*!#)-*#-#*K0-2-#
%&"(%+$,&#"0(%*'8*-.#'*#*--9,"1-#"-.#/"(:*,0(-.#-%20&#,#&,%&&0#/"("#2%K,(#.,#"#)"1,9"#
/-2,("# -'# 10-# .,(# (,2%(,)%-1"2"# 1"# 9"(&'("# -'# 1"# "90'("6# $-(# ,1,*/9-!#
%&"(%+$,&-,()0<GT%$&!# <&(5<0G(+,"&/# 2,0,(*%1"# >',# "# )"1,9"# /-2,# 0,(# .-*,10,# .'"#
9"(&'("#'-%20&+#"'*,10"2"#-'#2%*%1'82"#/,9-#'.'"(%-6#
$"("# )-*/9,0"(!# -# *K0-2-# 0(0,&# K# -# (,./-1."+,9# /,9-# 080'9-# 2"# )"1,9"!# >',#
"/"(,),#0"10-#1"#*"(("#2,#080'9-#>'"10-#1-#(-2"/K#2-#.,'#*-1%0-(#>'"12-#"#)"1,9"#K#
*%1%*%K"2"6#N#/"(:*,0(-#,./,("2-#K#'*"#.0(%1&6#
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 46
N# ,1,*/9-# .,&'%10,# %9'.0("# 2'".# )"1,9".6# J# /(%*,%("# 10-# /-2,# .,(#
(,2%*,1.%-1"2"#,#"#-'0("#/-..'%#0"*"1&-.#*"1%*-#,#*81%*-6#N#F"1+".#K#2,$%1%2-#.Q#
/"("# >',# -# 0"*"1&-# %1%)%"9# 2"# )"1,9"# 10-# .,)"# -# /"2(0-6# <-0,# >',# )(%"*-.# 2'".#
)9"..,.!#'*"#/"("#)"2"# )"1,9"!#,# 0"**K*#2'".# %1.0:1)%".#2%$,(,10,.#2"#)9"..,# ,6#N#
*K0-2-#9+(!,##7#K#"/9%)"2-#"#)"2"#'*"#2,9".6#
#
# -*- coding: cp1252 -*- 
from Tkinter import * 
class Nao_Redimensiona: 
 def __init__(self,janela): 
 janela.resizable(width=False, height=False)janela.title('Não redimensiona!') 
 Canvas(janela, width=200, height=100, bg='moccasin').pack() 
 
class Tamanhos_Limite: 
 def __init__(self,janela): 
 janela.maxsize(width=300, height=300) 
 janela.minsize(width=50, height=50) 
 janela.title('Tamanhos limitados!') 
 Canvas(janela, width=200, height=100, bg='moccasin').pack() 
 
inst1, inst2 = Tk(), Tk() 
Nao_Redimensiona(inst1) 
Tamanhos_Limite(inst2) 
inst1.mainloop() 
inst2.mainloop() 
 
$=I'> !&$E*
#
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 47
6,/"(,X#>'"12-#-(2,1"*-.#>',#"#)"1,9"#10-#.,)"#(,2%*,1.%-1"+,9#/"("#9"2-#
1,1&'*!#-#*-00-#*"1%*%K"(#2"#*"(("#2,#080'9-#.,>',(#"/"(,),9#$-(#-'0(-#9"2-!#>'"12-#
)9%)"*-.#1-#*-00-#*"1%*%K"(#2"#-'0("# )"1,9"!#,9"#"..'*,# %*,2%"0"*,10,#-# 0"*"1&-#
*"1%*-#/,(*%0%2-!#EII#/-(#EII6#
6,/"(,# 0"**K*# )-*-# -# F"1+".# .,# *"10K*# %*/"..8+,9# S.# *'2"13".# 2,#
0"*"1&-#2"#)"1,9"#0-/.9,+,96#Y#/"("#>',#+-)b#1-0"..,#%..-#>',#0-(1"*-.9-#)-9-(%2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% (intens_vermelho, intens_verde, intens_azul) 
J#0'/9"#)-10K*#"#%10,1.%2"2,#2".#)-(,.#*".%)".#1"#$-(*"#2,#%10,%(-.#,10(,#I#,#
@AA6#J#.0(%1&#(,.'90"10,#'/"(,)%2"#)-*##38c602+#/-2,#.,(#'."2"#)-*-#/"(:*,0(-#1-#
9'&"(# 2-# 1-*,# 2".# )-(,.!# >'"12-# +-)b# >'%.,(# 2,$%1%(# '*# -%2&,06# $"("# /(-2'K%(# -#
*("1)-!# *".0"# '."(# %10,1.%2"2,# *"1%*"# 2".# )-(,.# ;# '@AA!# @AA!# @AA+!# ,# -# /(,0-# K#
$-(*"2-#/,9"#%10,1.%2"2,#*81%*"#;#'I!#I!#I+6#
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 48
N# /(-&("*"# .,&'%10,# 10-# K# .Q# '*# ,1,*/9-# /"("# "/(,12%K"2-W# ,9,# .,(+%("#
0"**K*#/"("#+-)b#$"K,(#)-**%1"37,.#2,#%10,1.%2"2,#2,#)-(,.#*".%)".#"0K#")&"(#'*"#
)-**%1"30-# %10,(,.."10,#/"("#.'"##;=6#<,9,!#"#)-(#2-#)8()'9-#),10("9#K#)"9)'9"2"#/-(#
*,%-# 2"# 0K)1%)"# *-.0("2"# ")%*"!# "# /"(0%(# 2"# %10,1.%2"2,# 2,# )-(,.# %1$-(*"2".# /,9-#
'.'"(%-6# P-)b# /-2,# )&,)"(# .,# -# (,.'90"2-# $%)-'# "&("2"+,9# /,9-# /(Q/(%-# )8()'9-6# 2,#
&-.0"(!#K#.Q#)-/%"(#"#.0(%1&#*-.0("2"#S#2%(,%0"#2-#*-00-#,#'."(#1-#.,'#)Q2%&-6#
 
from Tkinter import * 
class Palheta: 
 def __init__(self,raiz): 
 
 raiz.title("Palheta") 
 self.canvas=Canvas(raiz, width=200, height=200) 
 self.canvas.pack() 
 self.frame=Frame(raiz) 
 self.frame.pack() 
 
 self.canvas.create_oval(15, 15, 185, 185, 
 fill='white', tag='bola') 
 
 Label(self.frame,text='Vermelho: ').pack(side=LEFT) 
 self.vermelho=Entry(self.frame, width=4) 
 self.vermelho.focus_force() 
 self.vermelho.pack(side=LEFT) 
 Label(self.frame,text='Verde: ').pack(side=LEFT) 
 self.verde=Entry(self.frame, width=4) 
 self.verde.pack(side=LEFT) 
 Label(self.frame,text='Azul: ').pack(side=LEFT) 
 self.azul=Entry(self.frame, width=4) 
 self.azul.pack(side=LEFT) 
 
 Button(self.frame, text='Mostrar', 
 command=self.misturar).pack(side=LEFT) 
 
 self.rgb=Label(self.frame, text='', width=8, 
 font=('Verdana','10','bold')) 
 self.rgb.pack() 
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 49
 def misturar(self): 
 cor="#%02x%02x%02x" %(int(self.vermelho.get()), 
 int(self.verde.get()), 
 int(self.azul.get())) 
 self.canvas.delete('bola') 
 self.canvas.create_oval(15, 15, 185, 185, 
 fill=cor, tag='bola') 
 self.rgb['text'] = cor 
 self.vermelho.focus_force() 
 
inst = Tk() 
Palheta(inst) 
inst.mainloop() 
#
$=I'> !&$E*
#
2,#+-)b#&-.0-'#2,..,#"*"(,9-#*,%-#,.+,(2,"2-#)-*#'*#0->',#'/,>',1-+#2,#
"K'9#,#>',(#)-9-)".9-#)-*-#)-(#2,#$'12-#2,#'*#*-00-!#K#.Q#$"K,(#$51G1IJ')&)K0L6#
!##(+N+1$910%+0+9&!0#1)&1&%%#"1+)&4$+)#17+%+1&B(0+%14$&1#1$"$3%(#1&!0%&1
 #91B+,#%&"1'#%+1)+1'+(5+1>]0MM1#$1 #910(7#"1(!B3,()#"1)&1)+)#"61#
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 50
6?* 3$4$*&=I-$@>,>*!*S$I,"#$*&$*4$'I=*
#
 -2-.# -.# -%2&,0.# /-..',*# >'"0(-# *K0-2-.# >',# "0'"12-# ,*# )-1)'10-#
/,(*%0,*#2,0,(*%1"(#"#/-.%30-#,*#>',#'*#)9%>',#-)-((,'6#N.#,1,*/9-.#.,(0-#2"2-.#
"0("+K.#2,#):1+".,.#/-(>',#1,..,#0%/-#2,#-%2&,0.#,.0,.#/(-),2%*,10-.#.0-#*"%.#40,%.!#
*".#-.#*,.*-.#)-1),%0-.#+"9,*#/"("#>'"9>',(#-%2&,06#
N.#*K0-2-.#,(!'#+%##05-/#,#,(!'#+%##08-/#(,0-(1"*#".#)--(2,1"2".#5#,#8#2-#
)"10-#1-(-,.0,#2-#)"1+".#,*#(,9"30-#"#'*#.%.0,*"#2,#)--(2,1"2".#2-#.,'#*,.0(,#''*#
$("*,#-'#"#/(Q/(%"# )"1,9"# 0-/.9,+,9+!# )')"#/-.%30-#,#-(%,10"30-#10-#+,*#"-#)".-6#N.#
-'0(-.# 2-%.!#,(!'#+7#(!0&%5-/# ,#,(!'#+7#(!0&%8-/!# 20-# "# /-.%30-# ,*# >',# -)-((,'# '*#
)9%>',#,*#(,9"30-#"-#.%.0,*"#L2,.)-1&,)%2-M#2,#)--(2,1"2".#2-#.,'#*,.0(,6#N#/'9-#2-#
&"0-#K#>',#"#.%*/9,.#.'*0("30-#2-#(,.'90"2-#2,.0,.#>'"0(-#*K0-2-.#1-.#2"#"#/-.%30-#
2-#)9%>',#,*#0,(*-.#2-#.%.0,*"#2,#)--(2,1"2".#2-#F"1+".!#1-..-#+,9&-#"*%&-6#
2,)"#@)#'*#)"1+".#1"#.'"#"/9%)"30-#&("$%)"6#2,)"#
x_absoluto = C1.winfo_pointerx()#,#
x_origem = C1.winfo_rootx()6#\100-!#5++$"#,$0#1N15+#%(5&9#K#-#/-10-#,*#
>',.00-#1-#.%.0,*"#2,#)--(2,1"2".#2-#F"1+".6#
$"..-'#/,9"#.'"#)"*,3"#"#'0%9%2"2,#2,#2,.)-*(%(#"#/-.%30-#,*#>',#-)-((,'#-#
)9%>',V#2,#10-!#+,)"#'*"#2".#'0%9%2"2,.#*"%.#*".%)".#)-*#-#/(Q1%*-#,1,*/9-6#<,9,!#
'."*-.#,.0"#0K)1%)"#/"("#/,(*%0%(#"-#'.'"(%-#2,.,1&"(#9%1&".#S#+-10"2,!#.%*/9,.*,10,#
)9%)"12-#,*#2-%.#/-10-.#1"#0,9"6#J.#)--(2,1"2".#2,#2,.,1&-#2"#9%1&"#.0-#(,0%("2".#2"#
/-.%30-#2-.#)9%>',.#2-#'.'"(%-6#
 
from Tkinter import * 
class AutoCADE: 
 def __init__(self, raiz): 
 raiz.title('AutoCADÊ') 
 self.canvas=Canvas(raiz, width=300, height=300, 
 bg='#beff8c', cursor='hand2') 
 self.canvas.bind('<1>',self.desenhar) 
! " # $ % & ' ( ) % * + * , - # . % " * / * 0 1 & ' 2 % * 3 *
# 4 ! " # 5 $ 
 
6 % 7 ' 8 * 2 + 9 + 4 ! * / * : $ ' , % * , - # . % " * / * ' " 5 7 , * / * ! 2 . + * 7 % 2 # 5 ! $ + * 51
 self.canvas.pack() 
 
 def desenhar(self,event): 
 x_origem = self.canvas.winfo_rootx() 
 y_origem = self.canvas.winfo_rooty()

Continue navegando